我在运行这段代码时遇到了问题。它说触发器是用编译错误创建的,但没有解释错误所在,也没有给出任何输出。下面是我得到的代码和错误。我使用的是Oracle11gSQL,使用的是PL/ R1。
CREATE OR REPLACE TRIGGER checkRecommendedAge
BEFORE INSERT OR UPDATE ON Loan
FOR EACH ROW
DECLARE
borAge number;
ex exception;
BEGIN
SELECT count(*) INTO borAge
FROM Loan
WHERE dateOut =: new.dateOut;
IF borAge < 18 THEN
dbms.output.put_line('Row added to Book table succesful');
ELSE
raise ex;
END IF;
EXCEPTION
WHEN EX THEN
raise_application_error("Error");
END;
/
错误:
Warning: Trigger created with compilation errors.
SQL> SHOW ERRORS
Errors for TRIGGER CHECKRECOMMENDEDAGE:
LINE/COL ERROR
-------- -----------------------------------------------------------------
0/0 PLS-00801: internal error [ph2csql_strdef_to_diana:bind]
6/2 PL/SQL: SQL Statement ignored
7/7 PL/SQL: ORA-06544: PL/SQL: internal error, arguments:
[ph2csql_strdef_to_diana:bind], [], [], [], [], [], [], []
10/3 PL/SQL: Statement ignored
10/3 PLS-00201: identifier 'DBMS.OUTPUT' must be declared
17/2 PL/SQL: Statement ignored
17/27 PLS-00201: identifier 'Error' must be declared
任何帮助都将不胜感激
谢谢
发布于 2012-01-13 23:53:17
您指定的是dbms.output。尝试在触发器中使用dbms_output.put_line。
编辑:
您错误地调用了RAISE_APPLICATION_ERROR。首先,不要在这里使用双引号的字符串-这表示的是标识符,而不是字符串。其次,此过程的语法为:
raise_application_error(error_number, message[, {TRUE | FALSE}]);
See the documentation获取更彻底的治疗。
您还可能遇到可怕的"ORA-04091: Table XXXXX is mutating“错误,因为您正在从触发器触发的同一个表中进行选择。有关更多信息,请参阅this AskTom文章。
发布于 2012-01-14 02:34:33
试一试。
更改:
dbms.output
到dbms_output
dateOut =:
到dateOut =
raise_application_error("Error");
到raise_application_error('Error');
CREATE OR REPLACE TRIGGER checkRecommendedAge
BEFORE INSERT OR UPDATE ON Loan
FOR EACH ROW
DECLARE
borAge number;
ex exception;
BEGIN
SELECT count(*) INTO borAge
FROM Loan
WHERE dateOut = new.dateOut;
IF borAge < 18 THEN
dbms_output.put_line('Row added to Book table succesful');
ELSE
raise ex;
END IF;
EXCEPTION
WHEN EX THEN
raise_application_error('Error');
END;
/
发布于 2012-01-14 11:59:08
另外,
WHERE dateOut =: new.dateOut;
应该是:
WHERE dateOut = new.dateOut;
https://stackoverflow.com/questions/8851506
复制相似问题