我的包裹内有问题
这是代码:
CREATE OR REPLACE PACKAGE BODY emp_data IS
PROCEDURE open_emp_cur_var(cv_emp IN OUT rt_emp, p_your_choice IN NUMBER)
IS
BEGIN
CASE
when p_your_choice=1 then open cv_emp for SELECT * FROM employees;
else OPEN cv_emp for SELECT * FROM employees WHERE salary > 8000;
end;
end;
end open_emp_cur_var;
END emp_data;
它返回给我它被编译为错误。
这是我返回的两个错误。
8/16 PLS-00103: Encountered the symbol ";" when expecting one of the following: case The symbol "case" was substituted for ";" to continue.
11/1 PLS-00103: Encountered the symbol "END"
答案 0 :(得分:2)
如果您不熟悉IF..END IF
,则可以使用CASE
此外,您可能正在寻找REFCURSOR
OUT
变量。
CREATE OR REPLACE PACKAGE emp_data IS
PROCEDURE open_emp_cur_var (
cv_emp OUT SYS_REFCURSOR , p_your_choice IN NUMBER
);
END;
/
CREATE OR REPLACE PACKAGE BODY emp_data IS
PROCEDURE open_emp_cur_var (
cv_emp OUT SYS_REFCURSOR, p_your_choice IN NUMBER
) IS
BEGIN
IF p_your_choice = 1 THEN
OPEN cv_emp FOR SELECT *
FROM employees;
ELSE OPEN cv_emp FOR SELECT *
FROM employees
WHERE salary > 8000;
END IF;
END;
END emp_data;
/
答案 1 :(得分:2)
您的第一个END
必须是END CASE
;并且您还有一个额外的END
:
CREATE OR REPLACE PACKAGE BODY emp_data IS
PROCEDURE open_emp_cur_var(cv_emp IN OUT rt_emp, p_your_choice IN NUMBER)
IS
BEGIN
CASE
WHEN p_your_choice=1 THEN
OPEN cv_emp for SELECT * FROM employees;
ELSE
OPEN cv_emp for SELECT * FROM employees WHERE salary > 8000;
END CASE;
END open_emp_cur_var;
END emp_data;
/