ORA-01722: invalid number 异常【我改】

我的情况是,在sql中两个字段相等最为条件时,这两个字段一个类型是字符串,一个是数字,而字符串类型的字段中有一条记录不能转成为数字造成的,解决方法,用 to_char将数字类型的字段转换为字符串再比较。

转:

ORA-01722: invalid number

如果某一个列定义的是varchar2字符串类型的,查询的时候使用了where xxx=1,让列名等于一个数字,那么,如果这个列里面都是数字,那么不报错,如果列里面只要有一个是非数字的,则报错。
因为,oracle使用了隐式的转换,to_number(xxx)=1,如果xxx列里面有不能转换为数字的,则报错。

下面进行验证
SQL> create table gw1(name varchar2(5));
Table created.
SQL> insert into gw1 values(1);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from gw1 where name=1;
NAME
----------
1
SQL> truncate table gw1;
Table truncated.
SQL> insert into gw1 values(‘a‘);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from gw1 where name=1;
select * from gw1 where name=1
                        *
ERROR at line 1:
ORA-01722: invalid number
SQL> insert into gw1 values(1);  
1 row created.
SQL> insert into gw1 values(2);
1 row created.
SQL> commit;
Commit complete.
SQL> select * from gw1 where name=1;
select * from gw1 where name=1
                        *
ERROR at line 1:
ORA-01722: invalid number

SQL> explain plan for select * from gw1 where name=1;
Explained.
SQL> select * from table(dbms_xplan.display);
PLAN_TABLE_OUTPUT
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Plan hash value: 3401378285
--------------------------------------------------------------------------
| Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------
|   0 | SELECT STATEMENT  |      |     1 |     4 |     3   (0)| 00:00:01 |
|*  1 |  TABLE ACCESS FULL| GW1  |     1 |     4 |     3   (0)| 00:00:01 |
--------------------------------------------------------------------------
Predicate Information (identified by operation id):
---------------------------------------------------
   1 - filter(TO_NUMBER("NAME")=1)----------------------------

然后检查两个用户的两个表,发现不报错的用户的表里面的字段都是数字,而报错的用户表里面的字段有字母。
————————————————
版权声明:本文为CSDN博主「娜然」的原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/nanaranran/article/details/79670873

原文地址:https://www.cnblogs.com/libin6505/p/12092862.html

时间: 2024-10-26 01:01:29

ORA-01722: invalid number 异常【我改】的相关文章

解决sqoop报错Invalid number; item = ITEM_UNICODE

报错栈: java.sql.SQLException: Invalid number; item = ITEM_UNICODE at com.intersys.jdbc.SysList.getInt(SysList.java:1735) at com.intersys.jdbc.CacheResultSet.getInt(CacheResultSet.java:247) at org.apache.sqoop.lib.JdbcWritableBridge.readInteger(JdbcWrit

讨厌麻烦的ora 01722无效数字

webservice开发过程中,数据库由原来的oracle改为现在的sql server.然后重新调试,结果报出ora 01722无效数字的错误. 由于连接oracle数据库的时候并没有问题,所以一开始我以为是数据库不同,导致部分数据类型差异,(但又觉得有点离谱,切换数据库,不至于会导致这种错误吧) 经过排查,总结得出如下: 1.对于两个类型不匹配(一个数字类型,一个非数字类型,同下)的值进行赋值操作;2.两个类型不匹配的值进行比较操作(例如,"=");3.to_number函数中的值

ORA-01722: invalid number

---问题 select owner,index_name,DEGREE from DBA_INDEXES where DEGREE>1 * ERROR at line 1: --1 获取执行跟踪信息 SQL> set autotrace traceonly SQL> select owner,index_name,DEGREE from DBA_INDEXES where DEGREE=1 and rownum<2; Elapsed: 00:00:00.05 Execution

ORA-01722: invalid number,ORA-12801

SQL: SELECT /*+ parallel(a,32) */ a.id           ,a.data_date           ,a.mobile_num           ,a.mobile_code           ,b.prov AS mobile_prov           ,b.city AS mobile_city           ,b.mobile_oper           ,a.psam           ,a.psam_code        

&#39;Invalid update: invalid number of rows in section xx. The number of rows contained in an existing section after the update (xxx)...

'Invalid update: invalid number of rows in section 5.  The number of rows contained in an existing section after the update (299) must be equal to the number of rows contained in that section before the update (276), plus or minus the number of rows

check_jmx4perl 1.10 findDeadlockedThreads ERROR &quot;Invalid number of operation arguments&quot;

Hi, The problem is:$ check_jmx4perl --url http://localhost:8081/jolokia --mbean java.lang:type=Threading --operation findDeadlockedThreads --null no-deadlock --string 1 --critical \!no-deadlock --critical 10UNKNOWN - Error: 400 java.lang.IllegalArgum

&#39;Invalid update: invalid number of sections. The number of sections contained in the table view aft

问题:(删除tableview中的section时) Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Invalid update: invalid number of sections.  The number of sections contained in the table view after the update (5) must be equal to th

The currently displayed page contains invalid values异常

1 项目丢失了default.properties这个文件会导致,从别的项目中拷贝一个过来,修改成对应的target即可 2.当eclipse遇到版本不兼容adt,导致adt没有下载完全,但eclipse只是禁用了这个adt没有把它卸载掉,"Help" -> "Software Updates" -> "Manage Configuration" Android的开发插件,单击选择之后,在右边框里选择"Disable&quo

问题:oracle 计算年龄;结果:oracle中根据生日计算年龄的问题

SELECT FLOOR(MONTHS_BETWEEN(SYSDATE,birthday)/12,1) FROM ltteacherinfo where name='朱雪东111'这个报错ORA 00909 :invalid number of arguments这个是怎么错了,计算年龄该怎么算,年龄要整数 --计算员工年龄SELECT FLOOR(MONTHS_BETWEEN(SYSDATE,birthdate)/12) FROM   ps_personal_data