触发器未找到数据问题
时间:2011-10-12
来源:互联网
刚学数据库,在学习触发器时出现如下问题:
SQL CODE:
create or replace trigger insert_ll
before insert on ll
--after inert on ll
referencing new as new old as old
for each row
declare
d_a char(10);
d_b number(10);
PRAGMA AUTONOMOUS_TRANSACTION;
begin
select ll.a,ll.b into d_a,d_b from ll where ll.a = :new.a;
if inserting then
insert into ll1(a,b)values(d_a,d_b);
end if;
commit;
end insert_ll;
在执行数据插入前 ll表有1条数据
a b
1 100
当我执行insert into ll values('2',200);语句时报如下错误:
ora-01403:未找到数据
ora-06512:在system.insert_ll,line 6
ora-04088:触发器system.insert_ll执行过程中出错
请问各位这个问题怎么解决啊。
SQL CODE:
create or replace trigger insert_ll
before insert on ll
--after inert on ll
referencing new as new old as old
for each row
declare
d_a char(10);
d_b number(10);
PRAGMA AUTONOMOUS_TRANSACTION;
begin
select ll.a,ll.b into d_a,d_b from ll where ll.a = :new.a;
if inserting then
insert into ll1(a,b)values(d_a,d_b);
end if;
commit;
end insert_ll;
在执行数据插入前 ll表有1条数据
a b
1 100
当我执行insert into ll values('2',200);语句时报如下错误:
ora-01403:未找到数据
ora-06512:在system.insert_ll,line 6
ora-04088:触发器system.insert_ll执行过程中出错
请问各位这个问题怎么解决啊。
作者: lilin0691 发布时间: 2011-10-12
提示的错误很明确,ora-01403:未找到数据
因为在执行select ll.a,ll.b into d_a,d_b from ll where ll.a = :new.a;的时候出现错误。
insert into ll values('2',200); 此时 new.a=2
你ll表中没有 a=2的记录,所以报错。
你执行insert into ll values('1',200); 就没错了。
或者加个异常处理。如
SQL code
因为在执行select ll.a,ll.b into d_a,d_b from ll where ll.a = :new.a;的时候出现错误。
insert into ll values('2',200); 此时 new.a=2
你ll表中没有 a=2的记录,所以报错。
你执行insert into ll values('1',200); 就没错了。
或者加个异常处理。如
SQL code
create or replace trigger insert_ll before insert on ll referencing new as new old as old for each row declare d_a char(10); d_b number(10); PRAGMA AUTONOMOUS_TRANSACTION; begin select ll.a, ll.b into d_a, d_b from ll where ll.a = :new.a; if inserting then insert into lll (a, b) values (d_a, d_b); end if; commit; exception when others then return; end insert_ll;
作者: jdsnhan 发布时间: 2011-10-13
你的逻辑有问题,你想把新插入的值插入到另一张表里去
实际很简单
直接
insert into lll(a, b) values(:new.a, :new.b);
实际很简单
直接
insert into lll(a, b) values(:new.a, :new.b);
作者: opps_zhou 发布时间: 2011-10-13
SQL code
同一楼的写法.....!!
作者: cosio 发布时间: 2011-10-13
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28