create or replace PROCEDURE CREATE_DEL_DEPT <br>
(
PARAM1 IN VARCHAR2 Default '%',
PARAM2 IN VARCHAR2 Default '%',
PARAM3 IN BOOLEAN Default True
) AS
PRAGMA AUTONOMOUS_TRANSACTION;
CURSOR Employees IS
Select Employee_ID, First_name, Last_Name
From HR.employees Where Department_ID = PARAM2;
BEGIN
For Employee_ID in Employees LOOP
if Department_ID = 20 then
DBMS_OUTPUT.PUT_LINE ('test');
elsif Department_ID = 30 then
DBMS_OUTPUT.PUT_LINE ('test1');
else
DBMS_OUTPUT.PUT_LINE ('else test');
end if;
END LOOP;
END;
我遇到以下错误。第14行是'If'语句的开始位置
错误(14,9):PL / SQL:语句已忽略
答案 0 :(得分:1)
从光标表中进行选择时,您需要参考department_id
CREATE OR REPLACE PROCEDURE create_del_dept
(
PARAM1 IN VARCHAR2 Default '%',
PARAM2 IN VARCHAR2 Default '%',
PARAM3 IN BOOLEAN Default True
) AS
PRAGMA AUTONOMOUS_TRANSACTION;
CURSOR Employees IS
Select Employee_ID, First_name, Last_Name,department_id
From HR.employees Where Department_ID = PARAM2;
BEGIN
for rec in employees LOOP
IF
rec.department_id = 20
THEN
dbms_output.put_line('test');
ELSIF rec.department_id = 30 THEN
dbms_output.put_line('test1');
ELSE
dbms_output.put_line('else test');
END IF;
END LOOP;
END;
/
通过使用隐式游标循环,可以简化代码,避免使用游标定义。
for rec in ( Select Employee_ID, First_name, Last_Name,department_id
From HR.employees Where Department_ID = PARAM2
) loop