oracle数据库报错ora-01722:invalid number,请哪位大神帮忙看看啊,很着急,只有这点分了
select b.serial_number,
b.user_id,
b.open_date,
a.attr_value,
h.cust_name,
c.fee,
d.fee,
e.fee,
f.fee,
g.fee,
o.fee,
i.state_name
from ucr_crm4.tf_f_user_item@crmrz a,
ucr_crm4.tf_f_user@crmrz b,
(select user_id, sum(fee) / 100 fee
from chan.hs_g_1207
group by user_id) c,
(select user_id, sum(fee) / 100 fee
from chan.hs_g_1208
group by user_id) d,
(select user_id, sum(fee) / 100 fee
from chan.hs_g_1209
group by user_id) e,
(select user_id, sum(fee) / 100 fee
from chan.hs_g_1210
group by user_id) f,
(select user_id, sum(fee) / 100 fee
from chan.hs_g_1210
group by user_id) g,
(select user_id, sum(fee) / 100 fee
from chan.hs_g_1211
group by user_id) o,
ucr_crm4.tf_f_customer@crmrz h,
(select *
from ucR_cen1.td_s_servicestate@crmrz
where service_id = '30000') i
where a.attr_value like '%华美汽配%'
and a.end_date >= sysdate
and a.user_id = b.user_id
and b.remove_tag = '0'
and b.user_id = c.user_id(+)
and b.user_id = d.user_id(+)
and b.user_id = e.user_id(+)
and b.user_id = f.user_id(+)
and b.user_id = g.user_id(+)
and b.cust_id = h.cust_id(+)
and b.user_id = o.user_id(+)
and b.user_state_codeset = i.service_id(+); 展开
数据库表中有一个varchar2类型的字段,里边可能包含数字或用逗号分隔的数据,如3或4,5这样的值,查询时,只传入了一个数字,也就是不带逗号的参数。因此sql语句类似这样:
select * from ct where nos = 3
语句本身一看就知道会出问题,因为3没加引号,会被当作数字处理。这样就肯定会报ORA-01722: invalid number的错误:
SQL Error: 1722, SQLState: 42000
ORA-01722: invalid number
但在用hibernate时,为了避免数字问题,我们经常会这样写hsql语句:
String sql = 'select * from ctEntity as ct where ct.Nos = ''+no+''';
当传入参数no为‘4,5’时,可能不会报错,但当no为'4'或'5'时,也就是单个数字时,就会报错了。经过打印hibernate的语句,发现单个数字时,hibernate会把上述语句转义成这样:
select ct.Nos from ctEntity as ct where ct.Nos=4
也就是会忽略掉引号,这样数据库就会报错,因为varchar2类型的nos字段在查询时给转义成了数字,所以肯定报错了。
这种情况下,hsql语句就不能用 ct.Nos = ' ***'这样的写法,必须用like,如ct.Nos like '%no%',这样才不会报错。当然完整的查询语句要考虑逗号的前、后以及没有逗号的情况,那就自己考虑了。
1、xxx.txt
文本内容:
XXXXXXXXXXXX XXXXX XXXXXXXXX X X X X XXXX
XXXXXXXXXXXX XXXXX XXXXXXXXX X X X X XXXX
2、XXX.ctl
....................................
INTO TABLE XXX_XXX_XXX -- 要插入记录的表
Fields terminated by ' ' -- 数据中每行记录用 空格 分隔
trailing nullcols --表的字段没有对应的值时允许为空
(
REQUEST_ID,
REQUEST_TIME DATE 'YYYYMMDDHH24MISS',
REQUEST_SOURCE INTEGER EXTERNAL ,
BUSINESS_TYPE INTEGER EXTERNAL ,
PAY_TYPE INTEGER EXTERNAL ,
CARD_WHOLECOUNT INTEGER EXTERNAL,
CARD_WHOLEVALUE INTEGER EXTERNAL,
PAY_AMOUNT INTEGER EXTERNAL
)
3、利用sqlloader导入会出现ORA-01722:invalid number问题;
原因:换行符的存在,如果integer或者number类型的栏位位于表的最后,最后其实会有CR/LF的换行符,在用sqlldr导入时会把换行符也算作那个数字的一部分,使得对应的导入PAY_AMOUNT 的值与PAY_AMOUNT在数据库中定义的NUMBE R(8)类型不匹配,从而出错。解决办法加integer或者加“TERMINATED BY WHITESPACE”。
即:
trailing nullcols --表的字段没有对应的值时允许为空
(
REQUEST_ID,
REQUEST_TIME DATE 'YYYYMMDDHH24MISS',
REQUEST_SOURCE INTEGER EXTERNAL ,
BUSINESS_TYPE INTEGER EXTERNAL ,
PAY_TYPE INTEGER EXTERNAL ,
CARD_WHOLECOUNT INTEGER EXTERNAL,
CARD_WHOLEVALUE INTEGER EXTERNAL,
PAY_AMOUNT INTEGER EXTERNAL TERMINATED BY WHITESPACE
)
注:在实际工程项目中,其实要导入9个字段,最后一个字段为导入时间,于是相应的在数据库中创表时,默认导入时间值为SYSDATE
IMPORT_DATE DATE DEFAULT SYSDATE
因为出现这个错误,说明你的查询结果,或者表关联时,某个字段里返回的数据或者相关联的两个字段的类型应该是number,但是,数据里有非number类型的.
where a.attr_value like '%华美汽配%' => where a.attr_value like "%华美汽配%"
FYR:
ORA-01722 invalid number
Cause: The attempted conversion of a character string to a number failed
because the character string was not a valid numeric literal. Only numeric fields
or character fields containing numeric data may be used in arithmetic functions
or expressions. Only numeric fields may be added to or subtracted from dates.
Action: Check the character strings in the function or expression. Check that
they contain only numbers, a sign, a decimal point, and the character "E" or "e"
and retry the operation.
广告 您可能关注的内容 |