我收到以下错误
Errors for TRIGGER TRIG:
LINE/COL ERROR
-------- -----------------------------------------------------------------
11/1 PL/SQL: SQL Statement ignored
11/37 PL/SQL: ORA-00911: invalid character
实际问题是:
考虑以下关系模式
Emp1
empid name salary dno
Del_History
dno Rows_deleted Date1
编写PL / SQL块以删除属于特定部门的所有员工的记录,然后在Del_History表中记录dno,删除的行数和删除日期。
create or replace trigger trig after delete on emp1 for each row
declare
d number:=&d;
begin
if deleting then
update Del_History set dno=d;
update Del_History set date1=sysdate;
update Del_History set Rows_deleted=%rowcount;
end if;
delete from emp1 where dno=d;
end;
答案 0 :(得分:0)
这可能不会直接回答您的问题,但发布的触发器的一些问题是:
您的触发器将在每行的表上删除后执行。您的触发器中不需要包含delete语句。删除已经发生。
要访问已删除行的列值,请使用:old.column。
由于这是行级触发器,因此sql%rowcount的值将始终为1.
context
不是必需的,因为触发器只是一个删除后触发器。
React Component
答案 1 :(得分:0)
我不认为需要触发器,因为实际问题是"写一个PL / SQL块" 。您将在下面找到一个匿名的PL / SQL block:
PL / SQL块由关键字DECLARE,BEGIN,EXCEPTION和END定义。这些关键字将块分为声明部分,可执行部分和异常处理部分。只需要可执行部分。
满足所有要求。
-- Write a PL/SQL block ...
declare
v_department_number constant number := 42;
v_rows_deleted number;
begin
-- ... to delete records of all employees who belong to
-- a particular department ...
delete from emp1 where dno = v_department_number;
-- record number of deleted rows
v_rows_deleted := sql%rowcount;
-- ... and then record the dno, no of rows deleted and date on
-- which deletion occurred in the Del_History table.
insert into del_history (
dno
,rows_deleted
,date1
) values (
v_department_number
,v_rows_deleted
,sysdate
);
end;
/