我在写一个触发器的时候,就是当A表的一个字段更新时,B表的相应字段也更新,但老是报错,是不是直接这样写不行?我考虑了一下,可能还有这种情况,就是当A表的一个字段更新时,B表也要存在相应的字段才行,那这一样一来的话,是写存储过程方便还是触发器方便?如果可以最好能写个示例,谢谢!
解决方案 »
- 请教达人翻译这个单词,找了一个又一个还是不怎么贴切,单词如下:literal ,主要是在ORACLE中
- RAC 两个节点之间为什么有一个ip ping不通
- 求助:oracle 10g 客户端可不可以连接oracle 9i服务器啊?怎么连啊?急!!!!
- ORA-12560: TNS: 协议适配器错误
- 请问大家有没有oracle联机热备、恢复的文档
- Oracle9i的sqlplus能连接Oracle 7.2.3的服务器吗?
- oracle安装完之后出现的问题
- 讨论-2:怎么理解“索引” 与 “约束条件”?他们的区别与联系是怎么样的?
- delphi环境下如何调用PL/SQL程序块
- 同时求上周销量和本周销量,本年销量 并求周上升幅度
- 怎样查看所定义过的存储过程列表,另外查看某个存储过程的定义吗
- Oracle 简单存储过程! 就一条select语句!
--如果A表的id在B表不存在,那么就更新不到B表create or replace trigger trigger_name
after update on A
for each row
begin
update B set b1=:new.a1 where id=:new.id;
end;
就是当A表的一个字段更新时,B表的相应字段也更新 要有对应的连接字段才行
create or replace trigger up_tbb before update on tba for each row
as
begin
update tbb set col1=:new.col1 where col:=:new.col;
end;
这种类似判断这条记录存不存在的做法呢?
declare
v_count number;
begin
select count(1) into v_count from tbb where col=:new.col;
if v_count>0 then
update tbb set col1=:new.col1 where col:=:new.col;
end if;
end;
if v_count>0 then
就把查到的这条记录插入到另一张表里,你看怎么写比较简洁一点?
declare
v_count number;
begin
select count(1) into v_count from tbb where col=:new.col;
if v_count>0 then
insert into tbb values(:new.col1);
end if;
end;
update on tb for each row
declare
v_count number;
begin select count(1) into from tb where col=:good.col
if v_count>0
insert into tb values(good.col);
end if;
end;
/