ITPub博客

首页 > 数据库 > Oracle > ora 1722无效的数字

ora 1722无效的数字

原创 Oracle 作者:oracle_mao 时间:2013-12-31 10:17:12 0 删除 编辑

 
SQL> create table tmao (id varchar2(64))

  2 
SQL> create table tmao (id varchar2(64));
 
Table created
 
SQL> insert into tmao values(818);
 
1 row inserted
 
SQL> insert into tmao values('819');
 
1 row inserted
 
SQL> commit;
 
Commit complete
 
SQL> select * from tmao where id=818;
 
ID
----------------------------------------------------------------
818
 
SQL> select * from tmao where id=819;
 
ID
----------------------------------------------------------------
819
 
SQL> insert into tmao values('4r');
 
1 row inserted
 
SQL> commit;
 
Commit complete
 
SQL> select * from tmao where id=819;
 
select * from tmao where id=819
 
ORA-01722: invalid number

SQL> create index inf on tmao(to_number(id));
 
create index inf on tmao(to_number(id))
 
ORA-01722: invalid number


最开始发起这个事情的原因,是开发人员问我,为啥在生产上执行id=819,不需要加引号就可以查不出来结果,而测试环境就需要加引号才可以查出来,如果不加引号就报错,无效的数字。其实做完实验,会发现很简单,原因就是id这是varchar2类型的,当我们不加引号的时候,走的是全表扫描,所以当扫描到不是纯数字的行时就会报错。

 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24500180/viewspace-1065871/ ,如需转载,请注明出处,否则将追究法律责任。

上一篇: tkprof的用法
请登录后发表评论 登录
全部评论

注册时间:2011-03-28

  • 博文量
    94
  • 访问量
    787850