ORA-01722: 无效的数字行以逗号传输 VARCHAR2 开头 TO_NUMBER
ORA-01722: invalid number rows start with comma transfer VARCHAR2 TO_NUMBER
我有以下 VARCHAR2 格式的源数据
,00100000004749745
,100000001490116
,125
,200000002980232
,25
,439999997615814
,5
0
1
1,10000002384186
1,5
100
2,1800000667572
3
3,29999995231628
96
999
将其转换为 NUMBER 的公式是什么?
与以下
INSERT INTO table_b.column_b
SELECT
TO_NUMBER (column_a,'9999999999D9999999999999999999999',
'nls_numeric_characters= ''.,''') as my_numbers
FROM table_a.column_a;
我收到一个错误
ORA-01722: invalid number error message.
我假设这是因为行以逗号开头,例如 (,125).
在目的地table我需要这样的数字格式的数据
0,00100000004749745
0,100000001490116
0,125
0,200000002980232
0,25
0,439999997615814
0,5
0
1
...
还尝试在逗号前放置零“0”,然后他们将其更改为带有
的数字
Select
column_a,
TO_NUMBER (column_a,'9999D9999999999999999999999',
'nls_numeric_characters= ''.,''') as my_number
from
(SELECT DISTINCT
'0'|| column_a
FROM table_a.column_a
WHERE column_a LIKE (',125')
);
但结果是
0,125 125
您似乎使用了错误的 nls_numeric_characters
值。尝试用 'nls_numeric_characters='', '''
替换 'nls_numeric_characters=''.,'''
解释:您的 nls_numeric_characters 将 .
定义为小数分隔符,将 ,
定义为组分隔符,但是,根据您的示例,您假设小数分隔符是 ,
正如 Vasyl 所说,您的 nls_numeric_characters
需要调整。下面的查询演示了如何将字符串转换为数字。
WITH
my_numbers (column_a)
AS
(SELECT ',00100000004749745' FROM DUAL
UNION ALL
SELECT ',100000001490116' FROM DUAL
UNION ALL
SELECT ',125' FROM DUAL
UNION ALL
SELECT ',200000002980232' FROM DUAL
UNION ALL
SELECT ',25' FROM DUAL
UNION ALL
SELECT ',439999997615814' FROM DUAL
UNION ALL
SELECT ',5' FROM DUAL
UNION ALL
SELECT '0' FROM DUAL
UNION ALL
SELECT '1' FROM DUAL
UNION ALL
SELECT '1,10000002384186' FROM DUAL
UNION ALL
SELECT '1,5' FROM DUAL
UNION ALL
SELECT '100' FROM DUAL
UNION ALL
SELECT '2,1800000667572' FROM DUAL
UNION ALL
SELECT '3' FROM DUAL
UNION ALL
SELECT '3,29999995231628' FROM DUAL
UNION ALL
SELECT '96' FROM DUAL
UNION ALL
SELECT '999' FROM DUAL)
SELECT n.column_a,
TO_NUMBER (n.column_a,
'9999999999D9999999999999999999999999999',
'nls_numeric_characters= '', ''') AS column_a_as_number
FROM my_numbers n;
我有以下 VARCHAR2 格式的源数据
,00100000004749745
,100000001490116
,125
,200000002980232
,25
,439999997615814
,5
0
1
1,10000002384186
1,5
100
2,1800000667572
3
3,29999995231628
96
999
将其转换为 NUMBER 的公式是什么?
与以下
INSERT INTO table_b.column_b
SELECT
TO_NUMBER (column_a,'9999999999D9999999999999999999999',
'nls_numeric_characters= ''.,''') as my_numbers
FROM table_a.column_a;
我收到一个错误
ORA-01722: invalid number error message.
我假设这是因为行以逗号开头,例如 (,125).
在目的地table我需要这样的数字格式的数据
0,00100000004749745
0,100000001490116
0,125
0,200000002980232
0,25
0,439999997615814
0,5
0
1
...
还尝试在逗号前放置零“0”,然后他们将其更改为带有
的数字Select
column_a,
TO_NUMBER (column_a,'9999D9999999999999999999999',
'nls_numeric_characters= ''.,''') as my_number
from
(SELECT DISTINCT
'0'|| column_a
FROM table_a.column_a
WHERE column_a LIKE (',125')
);
但结果是
0,125 125
您似乎使用了错误的 nls_numeric_characters
值。尝试用 'nls_numeric_characters='', '''
'nls_numeric_characters=''.,'''
解释:您的 nls_numeric_characters 将 .
定义为小数分隔符,将 ,
定义为组分隔符,但是,根据您的示例,您假设小数分隔符是 ,
正如 Vasyl 所说,您的 nls_numeric_characters
需要调整。下面的查询演示了如何将字符串转换为数字。
WITH
my_numbers (column_a)
AS
(SELECT ',00100000004749745' FROM DUAL
UNION ALL
SELECT ',100000001490116' FROM DUAL
UNION ALL
SELECT ',125' FROM DUAL
UNION ALL
SELECT ',200000002980232' FROM DUAL
UNION ALL
SELECT ',25' FROM DUAL
UNION ALL
SELECT ',439999997615814' FROM DUAL
UNION ALL
SELECT ',5' FROM DUAL
UNION ALL
SELECT '0' FROM DUAL
UNION ALL
SELECT '1' FROM DUAL
UNION ALL
SELECT '1,10000002384186' FROM DUAL
UNION ALL
SELECT '1,5' FROM DUAL
UNION ALL
SELECT '100' FROM DUAL
UNION ALL
SELECT '2,1800000667572' FROM DUAL
UNION ALL
SELECT '3' FROM DUAL
UNION ALL
SELECT '3,29999995231628' FROM DUAL
UNION ALL
SELECT '96' FROM DUAL
UNION ALL
SELECT '999' FROM DUAL)
SELECT n.column_a,
TO_NUMBER (n.column_a,
'9999999999D9999999999999999999999999999',
'nls_numeric_characters= '', ''') AS column_a_as_number
FROM my_numbers n;