Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

to_number() with format pattern and nvarchar2

782507Jul 1 2010 — edited Jul 1 2010
Hi,

I've had a problem with converting a number in US format in to a number. Due to the settings of our Oracle we have German locale settings. Thus I use the NLS format parameters in the to_number function. It works pretty well if I set the number string directly into the function call. However it did not work a the column of type nvarchar2 (which is actually permitted according to the documentation). This simple statement shows the problem:

alter session set NLS_NUMERIC_CHARACTERS = ',.';
DECLARE
evalue NVARCHAR2(20);
evalue2 NUMBER(25, 15);
BEGIN
SELECT '5.124' INTO evalue FROM dual;
SELECT to_number(evalue,
'9G990D9999999999999999999',
'NLS_NUMERIC_CHARACTERS = ''.,''') s
INTO evalue2
FROM dual;
dbms_output.put_line(evalue2);
END;

It gives me an ORA-01722 invalid number. It can be fixed by changing the column to e.g. VARCHAR(20) or just use an cast before passing to the to_number()

DECLARE
evalue NVARCHAR2(20);
evalue2 NUMBER(25, 15);
BEGIN
SELECT '5.1234' INTO evalue FROM dual;
SELECT to_number(cast(evalue as varchar2(20)),
'9G990D9999999999999999999',
'NLS_NUMERIC_CHARACTERS = ''.,''') s
INTO evalue2
FROM dual;
dbms_output.put_line(evalue2);
END;

I played around with the number and found out that the specified NLS_NUMERIC_CHARACTERS is not applied when the column type is NVARCHAR2 and is still trying to convert it using the session's locale settings.

Does anybody know if this is fixed already in a later version?
System: Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bit

Kind regards,
Mario
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 29 2010
Added on Jul 1 2010
1 comment
1,706 views