[英]Getting error ORA-01722: invalid number, while running query
I am running below query and getting this error: 我正在查询下面运行,并得到此错误:
ORA-01722: invalid number
01722. 00000 - "invalid number"
*Cause: The specified number was invalid.
*Action: Specify a valid number.
select DECODE(upper(db_param_DATA_TYPE),'VARCHAR2',data_length,upper(db_param_DATA_TYPE),'DATE',data_length,
upper(db_param_DATA_TYPE),'NUMBER',decode(
nvl(
data_scale,
0
),
0,
nvl(
data_precision,
0
),
data_precision
|| '.'
|| data_scale
))
from db_param a
join all_tab_columns b on a.db_param_COL_NAME=b.column_name;
Your query tries to compare a numeric value( data_length
) with string type values 'VARCHAR2'
that yields to produce ORA-01722
. 您的查询尝试将数字值(
data_length
)与字符串类型值'VARCHAR2'
,以产生ORA-01722
。
I've just considered the following query which's using all_tab_columns
dictionary view as data source : 我刚刚考虑了以下查询,该查询使用
all_tab_columns
字典视图作为数据源:
select decode(upper(DATA_TYPE),
'VARCHAR2',
to_char(data_length),
-- if "to_char(data_length)" replaced with "data_length", you get ORA-01722
upper(DATA_TYPE),
'DATE',
data_length,
upper(DATA_TYPE),
'NUMBER',
decode(nvl(data_scale, 0),
0,
nvl(data_precision, 0),
data_precision || '.' || data_scale))
from all_tab_columns b
where b.column_name = upper('&i_column_name'); -- a column in any table of the db.
The issue lies in the way you have used decode
- it does not work in the way I think you think it works. 问题出在您使用
decode
的方式上-不适用于我认为您认为有效的方式。
You have said: 你说过:
DECODE(upper(db_param_data_type),
'VARCHAR2',
data_length,
upper(db_param_data_type),
'DATE',
data_length,
upper(db_param_data_type),
'NUMBER',
DECODE(NVL(data_scale, 0), 0, NVL(data_precision, 0), data_precision || '.' || data_scale))
but what I think you mean is: 但是我想你的意思是:
DECODE(upper(db_param_data_type),
'VARCHAR2',
data_length,
'DATE',
data_length,
'NUMBER',
DECODE(NVL(data_scale, 0), 0, NVL(data_precision, 0), data_precision || '.' || data_scale))
ie you did not need to repeat the upper(db_param_data_type)
throughout the decode. 即,您无需在整个解码过程中重复
upper(db_param_data_type)
。
Decode works by taking a value and then comparing it and outputting the various responses, like so: 解码通过获取一个值然后进行比较并输出各种响应来进行,如下所示:
decode (<value being checked>
<if val1>
<then output result1>
<if val2>
<then output result2>
...
<else output result_else>)
so you only ever define the value being checked right at the start. 因此,您只能在开始时就定义要检查的值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.