17,377
社区成员
发帖
与我相关
我的任务
分享
CREAT OR REPLACE TRIGGER TRIG_I
BEFORE UPDATE ON 表A
DECLARE IVSN NUMBER;
BEGIN
SELECT DISTINCT 字段六 INTO IVSN FROM 表B;
IF NEW.字段三NOT IN IVSN THEN
INSERT INTO 表B
SELECT 字段四,字段五,MAX(字段六)+1 AS 字段六
FROM 表B
GROUP BY 字段四,字段五;
END IF;
END;
这么写有问题,麻烦告诉我问题在哪里,初学者实在太笨了。
----建立这个触发器就能满足你的需求
create or replace trigger trig_T
before update on A表
for each row
begin
if :New.字段三 = 1 then
insert into B表
select 字段四, 字段五, 1 from B表 t where t.字段六 = 0;
end if;
end;
----建立这个触发器就能满足你的需求
create or replace trigger trig_T
before update on A表
for each row
begin
if :New.字段三 = 1 then
insert into B表
select 字段四, 字段五, 1 from B表 t where t.字段六 = 0;
end if;
end;
SQL>
SQL> create table a(c1 varchar(10), c2 varchar(10), c3 int);
Table created
SQL> create table b(c1 varchar(10), c2 varchar(10), c3 int);
Table created
SQL> create trigger tri_a_up
2 before update on a
3 for each row
4 begin
5 insert into b values(:new.c1, :new.c2, :new.c3);
6 end;
7 /
Trigger created
SQL> insert into a values('A','B',0);
1 row inserted
SQL> insert into a values('C','D',0);
1 row inserted
SQL> update a set c3 = 1 ;
2 rows updated
SQL> select * from b;
C1 C2 C3
---------- ---------- ---------------------------------------
A B 1
C D 1
SQL> drop table a purge;
Table dropped
SQL> drop table b purge;
Table dropped
SQL>