I keep getting these errors, but can't seem to realize why. I'm new to oracle sql, so any help would be welcome! thanks in advance
CREATE OR REPLACE TRIGGER TRIGER1 AFTER DELETE OR INSERT ON LAB6_BILETI
FOR EACH ROW
DECLARE
CNT NUMBER;
CNP NUMBER;
BEGIN
SELECT COUNT(*) FROM T1 WHERE T1.T=:OLD.T INTO CNT
IF CNT=0 THEN
UPDATE T2 SET VP=1 WHERE T2.T=:old.T;
END IF;
SELECT COUNT(*) FROM T1 WHERE T1.T=:old.T AND T1.P=:old.P INTO CNP;
IF CNP=0 AND CNT!=0 THEN
UPDATE T2 SET VK=VK+1 WHERE T2.T=:old.T;
END IF;
END;
Errors:
Compilation failed, line 6 (16:27:48)
The line numbers associated with compilation errors are relative to the first BEGIN statement. This only affects the compilation of database triggers.
PL/SQL: ORA-00933: SQL command not properly ended
Compilation failed, line 5 (16:27:48)
PL/SQL: SQL Statement ignoredCompilation failed, line 7 (16:27:48)
PL/SQL: ORA-00933: SQL command not properly endedCompilation failed, line 7 (16:27:48)
PL/SQL: SQL Statement ignored Compilation failed, line 11 (16:27:48)
PLS-00103: Encountered the symbol "IF" when expecting one of the following:
; <an identifier> <a double-quoted delimited-identifier>
答案 0 :(得分:1)
您发布的触发器代码也有一些语法错误和一些逻辑错误。
语法错误是
逻辑上的缺陷是,对于INSERT触发器,:old
名称空间为空白,因此所选计数将始终为零,并且更新将丢失。 (也许这就是您想要的,但是如果是这样,您应该注释一下代码以达到这种效果。)更改此名称并不像替换:new
名称空间那样简单,因为在删除时该名称空间为空。
CREATE OR REPLACE TRIGGER TRIGER1 AFTER DELETE OR INSERT ON LAB6_BILETI
FOR EACH ROW
DECLARE
CNT NUMBER;
CNP NUMBER;
l_t t1.t%type;
l_p t1.p%type;
BEGIN
if deleting then
l_t := :OLD.T ;
l_p := :OLD.P ;
else -- inserting
l_t := :NEW.T ;
l_p := :NEW.P ;
end if;
SELECT COUNT(*) INTO CNT
FROM T1
WHERE T1.T= l_t ;
IF CNT=0 THEN
UPDATE T2
SET VP=1
WHERE T2.T= l_t;
END IF;
SELECT COUNT(*) INTO CNP
FROM T1
WHERE T1.T= l_t
AND T1.P= l_p;
IF CNP=0 AND CNT!=0 THEN
UPDATE T2
SET VK=VK+1
WHERE T2.T= l_t;
END IF;
END;
答案 1 :(得分:0)
我将使用简单的两个更新命令来代替这些INTERPROCEDURAL_OPTIMIZATION_<CONFIG>
和SELECT count(*) ...
:
IF cnt=0