动态声明光标或记录

时间:2014-06-19 09:52:33

标签: sql oracle dynamic cursor record

我们可以动态声明游标或记录吗?

CURSOR employee_id_cur
     IS
select * from <user entry table name> 

类似记录。

1 个答案:

答案 0 :(得分:0)

请参考以下示例:

DECLARE
TYPE EmpCurTyp IS REF CURSOR;
emp_cv EmpCurTyp;
emp_rec emp%ROWTYPE;
sql_stmt VARCHAR2(200);
my_job VARCHAR2(15) := 'CLERK';
BEGIN
    sql_stmt := 'SELECT * FROM emp WHERE job = :j';
    OPEN emp_cv FOR sql_stmt USING my_job;
    LOOP
        FETCH emp_cv INTO emp_rec;
        EXIT WHEN emp_cv%NOTFOUND;
        -- process record section.....
    END LOOP;
    CLOSE emp_cv;
END;

/