0
CREATE OR REPLACE TRIGGER check_enumber
BEFORE INSERT on emp
FOR EACH ROW
Declare result NUMBER;
dnumber NUMBER;
d_name VARCHAR(20);
Begin
check_eno(:new.ENO, result);
IF result = -1 THEN
RAISE_APPLICATION_ERROR (-20502, 'deptno already exist');
insert into emp_audit(ENO,ENAME,SAL,DNAME) values 
(:new.ENO,:new.ENAME,:new.SAL,:new.DNAME);
END IF;

IF Find_Dn(:new.DNAME) = 1 THEN
Select DNO, DNAME INTO dnumber, d_name
FROM dept
WHERE :new.DNAME = d_name;
:new.dno = dnumber;
IF d_name = 'SALES' THEN
:new.COMM := 300;
Update DEPT Set tot_sals = tot_sals + :new.SAL;
Update DEPT Set tot_emps = tot_emps + 1;  
END IF;
END IF; 
END;
/

LINE/COL 错误


16/13 PLS-00103:在预期以下情况之一时遇到符号“=”::=。( @ % ; 指示符 ":= 符号被插入到 "=" 之前以继续。

19/36 PLS-00103:在预期以下情况之一时遇到符号“_”:。( , * @ % & - + ; / at mod remaining rem return 返回 where || multiset 符号 ". 被插入到 "_" 之前以继续。

----------------------新代码和错误消息------------ ----------------

SQL> CREATE OR REPLACE TRIGGER check_enumber
  2  BEFORE INSERT on emp
  3  FOR EACH ROW
  4     Declare result NUMBER;
  5     dnumber NUMBER;
  6     d_name VARCHAR(20);
  7  Begin
  8   check_eno(:new.ENO, result);
  9   IF result = -1 THEN
 10     RAISE_APPLICATION_ERROR (-20502, 'deptno already exist');
 11     insert into emp_audit(ENO,ENAME,SAL,DNAME) values
 12             (:new.ENO,:new.ENAME,:new.SAL,:new.DNAME);
 13   END IF;
 14
 15   IF Find_Dname(:new.DNAME) = 1 THEN
 16     Select DNO, DNAME INTO dnumber, d_name
 17     FROM dept
 18     WHERE :new.DNAME :=d_name;
 19     :new.dno = dnumber;
 20     IF d_name = 'SALES' THEN
 21     :new.COMM := 300;
 22     Update DEPT Set tot_sals = tot_sals + :new.SAL;
 23     Update DEPT Set tot_emps = tot_emps + 1;
 24     END IF;
 25     END IF;
 26  END;
 27  /

警告:使用编译错误创建触发器。

SQL> 显示错误;TRIGGER CHECK_ENUMBER 的错误:

LINE/COL 错误


13/2 PL/SQL:SQL 语句被忽略 15/20 PL/SQL:ORA-01745:无效的主机/绑定变量名 16/11 PLS-00103:在预期以下之一时遇到符号“=”::=。( @ % ; 指示符 ":= 符号被插入到 "=" 之前以继续。

4

1 回答 1

0

我认为,这条线:new.dno = dnumber;导致了第一个问题(缺少冒号)。

应该改为:new.dno := dnumber;

对于第二个问题(谢谢Mr. Glenn),请更新(删除tot _sals中的空间)Update DEPT Set tot_sals = tot _sals + :new.SAL;

 Update DEPT Set tot_sals = tot_sals + :new.SAL;

line 似乎还有另一个问题WHERE :new.DNAME :=d_name;。请从语句中删除“:”为:

 WHERE :new.DNAME = d_name;
于 2012-10-18T02:18:53.033 回答