要求:
数据在insert 到表A前(一笔一笔Insert),如果表A的字段1的值存在于表B中的字段2中,则报错,数据无法insert到表A中。
这个触发器要怎么写呢。高人指点下。。
已经找到方法了。如下,
其中定义的变量为m,一开始定义成connt还不行。。。
create or replace trigger INSERT_AA
before insert on aa
For Each Row
declare
-- local variables here
m Number;
Begin
Select Count(*) Into m From bb Where BB.ID=:new.Id ;
If m>0 Then
raise_application_error(-20001,'error');
End If;
end INSERT_AA;
CREATE OR REPLACE TRIGGER TRI_T_A_FORINSERT
BEFORE INSERT ON A FOR EACH ROW
BEGIN
INSERT INTO A
VALUES
(:NEW.A1, :NEW.A2);
if (select 1 from B where b.b1 = :NEW.A1) = 1 then
RAISE_APPLICATION_ERROR('不能修改表');
end if;
END;
不知道这样子行不行 你看看 希望对你有帮助
不行呢,有提示
Compilation errors for TRIGGER BRISA.INSERT_AA
Error: PLS-00103: Encountered the symbol "SELECT" when expecting one of the following:
( - + case mod new not null others <an identifier>
<a double-quoted delimited-identifier> <a bind variable> avg
count current exists max min prior sql stddev sum variance
execute forall merge time timestamp interval date
<a string literal with character set specification>
<a number> <a single-quoted SQL string> pipe
<一个带有字符集说明的可带引号的字符串文字>
<一个可带引号的 SQ
Line: 7
Text: If (Select ID From BB Where BB.ID=:new.Id ) Then
Error: PLS-00103: Encountered the symbol ")" when expecting one of the following:
. ( * @ % & - + ; / at for mod remainder rem
<an exponent (**)> and or group having intersect minus order
start union where connect || indicator multiset
Line: 7
Text: If (Select ID From BB Where BB.ID=:new.Id ) Then