Select error ora 01722 invalid number

Have you gotten an “ORA-01722 invalid number” error? I’ll explain what this error is and how you can resolve it in this article.

Have you gotten an “ORA-01722 invalid number” error? I’ll explain what this error is and how you can resolve it in this article.

ORA-01722 Cause

The ORA-01722 error is caused by trying to convert a string into a number. It could be because of an invalid numeric character in your expression, or you’re trying to add a text value into a number column.

You’ve run an SQL query (which can be SELECT, INSERT, UPDATE, for example), and you’ve got this error:

ORA-01722: invalid number

The reason for this error is that Oracle has attempted to convert a string into a number, but could not perform the conversion.

For example, converting the value of “Hello” to a number cannot be done.

A valid number contains these characters:

  • Digits 0 to 9
  • Possibly a decimal point
  • A + or – sign
  • An E or e character

The error can appear in the following queries:

SELECT TO_NUMBER('123,100') FROM dual;

SELECT 'DatabaseStar' - 2016 FROM dual;

There are a few ways to resolve this error, so let’s take a look.

The solution to the “invalid number” error message could be one of several things:

  • An incorrect character or typo in your query
  • Bad data in your database
  • An issue with the query logic

1 – Mismatch of Data Types in an Insert Query

Are you trying to INSERT data into a table using INSERT INTO VALUES?

If so, check that your columns are aligned to your values. I mean, make sure that the position of the columns that contain numbers match the numbers you’re trying to insert.

This query will produce an error (assuming that score is a number):

INSERT INTO student_results (student_id, subject_name, score, comments)
VALUES (1, 'Science', 'Pretty good', 95);

I’ve got the columns around the wrong way here. To correct the query, I need to move the score value of 95 to in between the subject name and comments.

INSERT INTO student_results (student_id, subject_name, score, comments)
VALUES (1, 'Science', 95, 'Pretty good');

2 – Inserting or Updating using a Subquery

Are you inserting or updating values in a table using a subquery?

This error can be harder to detect, because you’re not explicitly stating the values to be inserted.

The error occurs because one of the values found in the subquery is trying to be inserted into a numeric column, and the value is not a number.

To find the cause of the error, you can run the subquery by itself and add a WHERE condition:

WHERE UPPER(column) != LOWER(column)

Replace the “column” with the column you suspect has the bad data. The UPPER and LOWER functions will return different values from character strings, and you should be left with the rows that have string values.

If you want to dig further, or if that doesn’t work:

  1. Run the subquery by itself to see the results
  2. Look at the values in the columns you’re expecting to be numeric to identify any that look like obvious characters.
  3. If you can’t easily tell, you can perform a TO_NUMBER on the columns to find the error.
  4. If this doesn’t help, try getting a DISTINCT list of each column in the subquery, and then performing a TO_NUMBER.
  5. You can also use a WHERE clause to restrict the results of the subquery, so you’re only looking at a small data set at a time.

Once you’ve found the value that causes the issue, you can either update the bad data, or update your query to handle this data.

3 – Implicit Conversion in a Select Statement

Are you getting this “ORA-01722 invalid number” error when running a SELECT statement?

There are a few reasons for this error:

  1. Implicit conversion in WHERE clause
  2. Invalid format mask when using TO_NUMBER

In most cases, it is due to an implicit conversion in a WHERE clause. An implicit conversion is where a value is being converted by Oracle but you didn’t specify it.

To resolve this, check for a numeric column that’s being compared to a character column.

For example:

SELECT ...
WHERE number_col = varchar_col;

This will result in an implicit conversion of the VARCHAR column to a number, which may cause the invalid number error.

If you’re using the TO_NUMBER function in your query, make sure that the format mask includes acceptable characters.

The earlier example would cause an error.

4 – Other Possible Solutions

There are some other solutions to this error:

  • Fields that contain spaces cannot be converted, so ensure that you TRIM this data, convert it to NULL or zero.
  • The database formats for numbers are mismatched between two databases. For example, European numeric data uses 12.345,67 where US format is 12,345.67. Review your NLS_LANG settings to ensure this isn’t causing any issues.
  • A function-based index on the table could be causing the error. Review your table to see if there are any function-based indexes that could be converting data.

So, that’s how you resolve the ORA-01722 invalid number error in Oracle!

Lastly, if you enjoy the information and career advice I’ve been providing, sign up to my newsletter below to stay up-to-date on my articles. You’ll also receive a fantastic bonus. Thanks!

Fix ORA-01722 Invalid Number Error

Using Oracle database is very common but sometimes due to some uncertain reasons, you may get ORA-01722 invalid number error. Do you want to know what is ORA-01722 invalid number error and how to resolve ora-01722 invalid number error? If you want to know so then I must say that you have come to the right place. I am saying so because here I am going to mention some best ways to fix ORA-01722 error in Oracle.

Now, let’s get started with the introduction of this error, causes and then the ways to fix ora-01722 invalid number error and so on…..

What Is ORA_01722 Invalid Number Error?

ORA-01722 invalid number error is actually a fairly typical error in Oracle database. It is an invalid number error that occurs during a failure when you convert a character string to a valid number. It is an error that occurs due to arithmetic operation in the statement failed to calculate just because a single operand cannot be implicitly converted to a valid number. This error can take place due to several reasons which are further mentioned in this blog, so do not skip going through this blog.

Causes Of Occurring ORA-01722 Invalid Number Error

Several causes are that can lead you to face ORA-01722 invalid number error. However, some of the major causes are as follows:

Cause #1: Error During String Concatenation

If you use a plus (add) sign then it cannot concatenate strings. So, if you are using a wrong sign to concatenate two strings then you can get ORA-01722 invalid number error. Below is the code you might have tried to concatenate two strings:

SQL> set heading off;
SQL> select ‘Today is ‘ + sysdate from dual;
select ‘Today is ‘ + sysdate from dual
*
ERROR at line 1:
ORA-01722: invalid number

Here, SQL parser thought the statement tried to make arithmetic operation, however, it failed to continue. The right ways to concatenate two strings are as follows:

SQL> select ‘Today is ‘ || sysdate from dual;

Today is 26-DEC-19

The output of this code is perfect in concatenating two strings.

Cause #2: Error During Type Conversion

When you create a simple table that contains only one column with NUMBER type with the below code:

SQL> create table salaries (salary number);

Table created.

If you try to insert a row into the table that contains NUMBER column, you may get ORA_01722 error with the below code:

SQL> insert into salaries (salary) values (‘200,000’);
insert into salaries (salary) values (‘200,000’)
*
ERROR at line 1:
ORA-01722: invalid number

You may get this error because the value ‘200,000’ of column SALARY can’t be converted into a valid number. You can make it easier by just removing the comma separator:

SQL> insert into salaries (salary) values (‘200000’);

1 row created.

When it comes to fixing ORA_01722 invalid number error, you can try several ways but the best options you can try are further mentioned here. All these solutions are very easy to try and are the most effective and working ways:

Fix #1: Insert Or Update Using a Subquery

If you are inserting or updating values in a table by using a subquery then you can get this error. This error can be quite difficult to detect because you are not explicitly stating the values to be inserted. You get this error because sometimes even one of the values found in the subquery is trying to be inserted into some numeric column. Also, the value is not a number.

Well, to find the major causes of this error, you can try running the subquery by itself and you can add a WHERE condition as mentioned below:

WHERE UPPER(column) != LOWER(column)

Here, you can replace the column with the column you found has the bad data. Here, the UPPER and the LOWER functions will return the different values from character strings and then you will be left with the rows that have strings values.

If you want to dig further then you can follow the below steps:

  • You can run the subquery by itself to check the results.
  • You can look at the values in the column you are expecting to be numeric to identify any that look like the same characters.
  • You can also perform a TO_NUMBER on the columns to find the error.
  • Also, you can get a DISTINCT list of each column in the subquery and then you can perform a TO_NUMBER.
  • Apart from this, you can use a WHERE clause to restrict the results of the subquery and so you are just looking at a small data set at a time.

After you found the value that causes this error, you can either update the bad data or you can update the query to properly handle this data.

Fix #2: Mismatch Of Data Types In An Insert Query

If you are trying to INSERT data into a table with the use of INSERT INTO VALUES?

If yes then you can check that the columns are aligned to the values you want. It means that you have to make sure that the position of the columns that used to contain numbers that you are trying to insert.

The below query will then produce ORA-01722 invalid number error:

INSERT INTO student_results (student_id, subject_name, score, comments)

VALUES (1, ‘Science’, ‘Pretty good’, 95);

After this query, you will get the columns around the wrong way and in order to correct the query, you have to move the score value of 95 to in between the comments and the subject name.

INSERT INTO student_results (student_id, subject_name, score, comments)

VALUES (1, ‘Science’, 95, ‘Pretty good’);

Fix#3:  Convert Implicitly In a Select Statement

If you are getting the error ‘ora-01722 invalid number’ when you are running a SELECT statement there would be two possible reasons:

  • Invalid format mask while using TO_NUMBER
  • Convert implicitly in WHERE clause

In some cases, this error takes place due to implicit conversion in a WHERE clause. An implicit conversion is where a value is being converted by Oracle but you do not specify it.

However, in order to fix this issue, you have to check for a numeric column that is being compared to a character column. As for example:

SELECT …

WHERE number_col = varchar_col;

This code insertion will result in an implicit conversion of the VARCHAR column to a number which may also cause the invalid number error.

However, if you are using the TO_NUMBER function in the query, you have to make sure that the format mask includes acceptable characters.

Fix #4: Some Common Possible Fixes

Apart from the above fixes, you can try these other possible ways to fix ORA-01722 invalid number error. Here are the other possible fixes you can try:

  • The database formats for numbers are mismatched between these two databases. As for example, European numeric data uses 12.345,67 where US format is 12,345.67. You can review the NLS_LANG settings to make sure that it is not causing any problem.
  • Fields that used to contain spaces cannot be easily converted, so it is important to make sure that you TRIM this data. After that, you convert it to NULL or also can convert it to ZERO.
  • It is possible that a function-based index is causing ORA_01722 invalid number error. You can review the table to see if there are any function-based indexes that could be converting the data.

Ultimate Solution: Oracle File Repair Tool To Fix ORA-01722 Invalid Number Error

Even after trying all the above ways, you are still unable to resolve ora-01722 invalid number then you can try Oracle File Repair Tool. This tool has the best features that can definitely let you know how to resolve ora-01722 invalid number error? You can just try this tool and fix ora-01722 invalid number error due to its great features. All you have to do is to download and install Oracle File Repair Tool to fix ora-01722 invalid number error.

Below, you will get the step by step guide to know how to resolve ora-01722 invalid number error with this best-featured tool.

Steps To Fix ORA-01722 Invalid Number Error

Step 1: Search the Initial screen of Stellar Phoenix Oracle Repair & Recovery with a pop-up window showing options to select or search corrupt Oracle databases on your computer.

1

Step 2: Click Scan File to initiate the scan process after selecting the oracle database. The recoverable database objects get listed in left-side pane.

2

Step 3: Click an object to see its preview.

3

Step 4: : Click Start Repair in the icon bar to start the repair process. A pop-up window is displayed which show the steps needed to perform further. Click next and continue.

4

Step 5: Give the user name, password and path of the blank database where you want to save the repaired database objects.

5

Step 6: Repairing and restoring various database objects after establishing a connection with blank oracle database.

6

Final Verdict

While using Oracle database, if you ever come across an error stated as ‘ORA-01722 Invalid Number’ then you should try these ways mentioned above. I have tried my best to provide you the working and the effective solution I can. However, if manual ways do not work in your case, then you can also try Oracle File Repair Tool. This tool has the capability to fix any kind of error related to Oracle database. So, know how to resolve ora-01722 invalid number error in Oracle database and recover the database easily in no time.

Jacob Martin is a technology enthusiast having experience of more than 4 years with great interest in database administration. He is expertise in related subjects like SQL database, Access, Oracle & others. Jacob has Master of Science (M.S) degree from the University of Dallas. He loves to write and provide solutions to people on database repair. Apart from this, he also loves to visit different countries in free time.

ORA-01722 means that the arithmetic operation in the statement failed to calculate because one of operands cannot be converted to a valid number implicitly.

Let’s see some error patterns.

A. Type Conversion

We created a simple table containing only one column with NUMBER type.

SQL> create table salaries (salary number);

Table created.

When we tried to insert a row into the table containing NUMBER column, we got ORA-01722.

SQL> insert into salaries (salary) values ('200,000');
insert into salaries (salary) values ('200,000')
                                      *
ERROR at line 1:
ORA-01722: invalid number

1. Make it Easier to Convert

This is because the value ‘200,000’ of column SALARY cannot be converted into a valid number. We should make it easier to be converted, so we remove the comma separator.

SQL> insert into salaries (salary) values ('200000');

1 row created.

Unsurprisingly, string ‘200000’ can be converted to a number and inserted into the table.

In fact, implicit conversion between different data types has some restrictions, I suggest that you use explicit conversion to make your codes robust.

2. Use VARCHAR2

You cannot always depend on unpredictable implicit conversion, sometimes, you should change the column from NUMBER into VARCHAR2. For example, phone numbers of customers may not be perfectly formatted as NUMBER.

SQL> insert into customers (cust_id, phone_number) values (100, '0254 539 2413');
insert into customers (cust_id, phone_number) values (100, '0254 539 2413')
                                                           *
ERROR at line 1:
ORA-01722: invalid number

As we can see, the value of phone number cannot be converted into a NUMBER, so we should use VARCHAR2 instead.

SQL> alter table customers modify phone_number varchar2(13);

Table altered.

SQL> insert into customers (cust_id, phone_number) values (100, '0254 539 2413');

1 row created.

B. String Concatenation

Using a plus (add) sign can not concatenate strings.

SQL> set heading off;
SQL> select 'Today is ' + sysdate from dual;
select 'Today is ' + sysdate from dual
       *
ERROR at line 1:
ORA-01722: invalid number

SQL parser thought your statement was trying to do an arithmetic operation, but the string ‘Today is ‘ failed to be converted into number. The correct way to concatenate strings is to use ||, not a plus sign +.

SQL> select 'Today is ' || sysdate from dual;

Today is 26-DEC-19

As a result, the output is perfect in concatenating a string and a date without ORA-01722.

A very similar error that you might see in your PL/SQL codes is ORA-06502: PL/SQL: numeric or value error, which is also related to conversion issues of numeric values.

Microsoft distributes Microsoft SQL Server 2008 Service Pack 2 (SP2) or Microsoft SQL Server 2008 R2 fixes as one downloadable file. Because the fixes are cumulative, each new release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 Service Pack 2 (SP2) or SQL Server 2008 R2 fix release.

Symptoms

Consider the following scenario:

  • You create a table that has a varchar (max) data type column in Microsoft SQL Server 2008 or in Microsoft SQL Server 2008 R2.

  • You try to replicate the table to an Oracle server subscriber, and you select Transactional publication as the publication type.

    Note The initial synchronization is successful.

  • You insert or update a long value record in the varchar (max) column of the table.

    For example, the value is more than 8200 characters long.


In this scenario, the Distribution Agent does not synchronize the new record to the Oracle server subscriber. Additionally, you receive the following error message:

Replication-Replication Distibution Subsystem: agent <agent name> failed. ORA-01722: invalid numberErrorId = 160, SourceTypeId = 16
ErrorCode = ‘1722’
ErrorText = ‘ORA-01722: invalid number’

Resolution

Cumulative update information

SQL Server 2008 R2


The fix for this issue was first released in Cumulative Update 9. For more information about how to obtain this cumulative update package for SQL Server 2008 R2, click the following article number to view the article in the Microsoft Knowledge Base:

2567713 Cumulative Update package 9 for SQL Server 2008 R2 Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 R2 fix release. We recommend that you consider applying the most recent fix release that contains this hotfix. For more information, click the following article number to view the article in the Microsoft Knowledge Base:

981356 The SQL Server 2008 R2 builds that were released after SQL Server 2008 R2 was released

SQL Server 2008 R2 Service Pack 1


The fix for this issue was first released in Cumulative Update 2 for SQL Server 2008 R2 Service Pack 1. For more information about how to obtain this cumulative update package, click the following article number to view the article in the Microsoft Knowledge Base:

2567714 Cumulative Update package 2 for SQL Server 2008 R2 Service Pack 1Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 R2 fix release. We recommend that you consider applying the most recent fix release that contains this hotfix. For more information, click the following article number to view the article in the Microsoft Knowledge Base:

2567616 The SQL Server 2008 R2 builds that were released after SQL Server 2008 R2 Service Pack 1 was released

SQL Server 2008 Service Pack 2


The fix for this issue was first released in Cumulative Update 4. For more information about how to obtain this cumulative update package for SQL Server 2008 SP2, click the following article number to view the article in the Microsoft Knowledge Base:

2527180 Cumulative update package 4 for SQL Server 2008 SP2Note Because the builds are cumulative, each new fix release contains all the hotfixes and all the security fixes that were included with the previous SQL Server 2008 SP2 fix release. We recommend that you consider applying the most recent fix release that contains this hotfix. For more information, click the following article number to view the article in the Microsoft Knowledge Base:

2402659 The SQL Server 2008 builds that were released after SQL Server 2008 SP2 was released

Status

Microsoft has confirmed that this is a problem in the Microsoft products that are listed in the «Applies to» section.

More Information

For more information about Oracle publishing, visit the following MSDN website:

General information about Oracle subscribersFor more information about snapshot replication, visit the following MSDN website:

General information about snapshot replication

Need more help?

Понравилась статья? Поделить с друзьями:

Читайте также:

  • Select corona as your production render first как исправить
  • Select action an error occurred while trying to copy a file
  • Segmentation fault core dumped как исправить
  • Segfault error linux
  • Segfault error codes

  • 0 0 голоса
    Рейтинг статьи
    Подписаться
    Уведомить о
    guest

    0 комментариев
    Старые
    Новые Популярные
    Межтекстовые Отзывы
    Посмотреть все комментарии