PL / SQL:语句被忽略

时间:2014-03-11 06:21:08

标签: plsql triggers

create or replace trigger perform_validations
after insert or update on xx_hr_employee
for each row
begin
validation;
END;
/

我的程序验证是:

declare
 E_ID xx_hr_employee.emp_id%type;
 E_NAME xx_hr_employee.emp_name%type;
 D_ID xx_hr_employee.dept_id%type;
 D_NAME xx_hr_employee.dept_name%type;
 S_ID xx_hr_employee.supervisor_id%type;
 S_NAME xx_hr_employee.supervisor_name%type;
 P_ID xx_hr_employee.project_id%type;
 P_NAME xx_hr_employee.project_name%type;
 SAL xx_hr_employee.salary%type;
 A xx_hr_employee.age%type;
 l_count number;
 e_count number;
procedure validation 
is
cursor my_cursor is
select EMP_ID, EMP_NAME, DEPT_ID, DEPT_NAME, SUPERVISOR_ID, SUPERVISOR_NAME, PROJECT_ID, PROJECT_NAME, SALARY, AGE
from xx_hr_employee  E;
begin

open my_cursor;
loop
fetch my_cursor into E_ID, E_NAME, D_ID, D_NAME, S_ID, S_NAME, P_ID, P_NAME, SAL, A;
exit when my_cursor%notfound;
if(E_ID = 0000) then
insert into xx_stg_hr_employee( EMP_ID, EMP_NAME, DEPT_ID, DEPT_NAME, SUPERVISOR_ID, SUPERVISOR_NAME, PROJECT_ID, PROJECT_NAME, SALARY, AGE) 
select EMP_ID, EMP_NAME, DEPT_ID, DEPT_NAME, SUPERVISOR_ID, SUPERVISOR_NAME, PROJECT_ID, PROJECT_NAME, SALARY, AGE from xx_hr_employee
where emp_id <> 0000;
end if;
end loop;
close my_cursor;

delete from xx_stg_hr_employee WHERE (Emp_name like '% %');


UPDATE xx_stg_hr_employee SET mycol=seq_id3.NEXTVAL;

Select count(*) into l_count From xx_hr_employee
Group By  EMP_ID, EMP_NAME, DEPT_ID, DEPT_NAME, SUPERVISOR_ID, SUPERVISOR_NAME, PROJECT_ID, PROJECT_NAME, SALARY, AGE 
Having Count(*) > 1;
if(l_count <> 0) then
delete from xx_stg_hr_employee where mycol NOT IN (SELECT MIN(mycol) 
    FROM xx_stg_hr_employee GROUP BY EMP_ID, EMP_NAME, DEPT_ID, DEPT_NAME, SUPERVISOR_ID, SUPERVISOR_NAME, PROJECT_ID, PROJECT_NAME, SALARY, AGE);

end if;

end;


 begin
    validation;
    end;
    /

它在第2行显示错误:PL / SQL:语句被忽略.. 这里验证是一个在xx_hr_employee上执行任何插入(或更新)时应调用的过程。 我不知道如何继续前进。 我正在使用oracle apex。

1 个答案:

答案 0 :(得分:0)

我测试了以下内容并且它对我有用,所以请看看你错过了什么:

例如 您的表格就像Create table TEST_TABLE (X Number);

然后您的存储过程是

CREATE OR REPLACE  PROCEDURE VALIDATIONS IS
BEGIN
     --Do your validation over here..
     UPDATE TEST_TABLE SET X = 1;
END;

那么你的代码应该像你写的那样工作:

CREATE OR REPLACE TRIGGER PERFORM_VALIDATIONS
AFTER INSERT OR UPDATE ON TEST_TABLE 
FOR EACH ROW
BEGIN
 VALIDATIONS;
END;
/

重要提示:如果您在程序包中创建过程,请确保Package head具有声明,然后仅将其称为YourPackageName.VALIDATIONS而不是VALIDATIONS