ORACLE 1722 错误案例分析


-- ORACLE 1722 错误案例分析

-- 1. 创建表
drop table area;
create table area (id number(10, 0) primary key, areacode varchar2(20));

-- 2. 插入正常数据
insert into area values (1, '10');
insert into area values (2, '20');
insert into area values (3, '30');
insert into area values (5, '40');
insert into area values (6, '50');
commit;

select * from area;
select * from area where areacode = 20;

-- 3.插入异常数据
insert into area values (7, '20
');
commit;

-- 4.报错1722 INVAID NUMBER 无效数字
select * from area where areacode = 20;

-- 5.问题定位
-- 查看是否有换行符 10 回车符 13 制表符 9
select id , areacode from area where length(replace(replace(areacode, chr(10), ''), chr(13), '')) < length(areacode);


-- 6.处理
delete from area where id = 7;
commit;

-- 7.问题引入分析
-- 插入数据时意外的插入了换行符.查询时SQL不符合规范.
-- 此字段本来用来存储字符数据,但ORACLE隐式转换字符为数字去比较.
-- 规范写法:
select * from area where areacode = '20';


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值