请帮我用refcursor编写程序程序。 Refcursor应该是参数。
如果我给输入deptno它显示该部门的员工详细信息,也写单元测试块:
我试过了:
var accessToken = model[selected].EmbedToken.Token;
///////单元测试/////
CREATE OR REPLACE PROCEDURE poph (i IN NUMBER, p OUT SYS_REFCURSOR)
IS
BEGIN
OPEN p FOR 'select * from emp where deptno=' || i;
FOR i IN p
LOOP
DBMS_OUTPUT.put_line (i.ename || '**' || i.JOB);
END LOOP;
CLOSE p;
END;
/
答案 0 :(得分:0)
你犯了两个错误。
1)打开动态select语句的refcursor,如果没有execute immediate语句,它将无效。
OPEN p FOR'select * from emp where deptno ='|| I;
2)循环通过无效的引用游标;
FOR i IN p
这样做:
CREATE OR REPLACE PROCEDURE poph (i IN NUMBER, p OUT SYS_REFCURSOR)
IS
v_sql varchar2(100);
BEGIN
v_sql := 'select employee_id,salary from employee where employee_id=' || i;
execute immediate v_sql;
OPEN p FOR v_sql;
END;
/
///////单元测试/////
DECLARE
M NUMBER := '&n';
n SYS_REFCURSOR;
v_emp_id NUMBER;
v_sal NUMBER;
BEGIN
poph (M, n);
LOOP
FETCH n INTO v_emp_id, v_sal;
EXIT WHEN n%NOTFOUND;
DBMS_OUTPUT.PUT_LINE (v_emp_id);
END LOOP;
END;