如何在带有过程的表中插入游标值

时间:2017-05-03 08:53:16

标签: oracle stored-procedures plsql oracle12c

我是oracle的新手..我想把光标的一些字段放到不同的表中。检查网上可用的选项,但没有为我工作。

    PROCEDURE get_emp_info (p_nbr_rec     IN     NUMBER DEFAULT 10,
                        p_emp_id      IN     NUMBER DEFAULT NULL,
                        p_user_id     IN     VARCHAR2 DEFAULT NULL,
                        rc_emp_info      OUT ref_cursor)
IS
BEGIN
   OPEN rc_emp_info FOR
      SELECT e.employee_id,
             e.user_id,
             e.first_name,
             e.preferred_name,
             e.last_name,
             e.manager_name,
             FROM employee e
   WHERE
   (p_user_id is NULL OR e.user_id = LOWER(p_user_id) )
end get_emp_info;

请帮助并提出相同的解决方案。 提前致谢。

1 个答案:

答案 0 :(得分:0)

    PROCEDURE get_emp_info (p_nbr_rec     IN     NUMBER DEFAULT 10,
                            p_emp_id      IN     NUMBER DEFAULT NULL,
                            p_user_id     IN     VARCHAR2 DEFAULT NULL,
                            rc_emp_info      OUT ref_cursor)
    IS
    BEGIN
-- Not sure why so many inputs when you are not using it
       OPEN rc_emp_info FOR
          SELECT e.employee_id,
                 e.user_id,
                 e.first_name,
                 e.preferred_name,
                 e.last_name,
                 e.manager_name
                 FROM employee e
       WHERE
       (p_user_id is NULL OR e.user_id = LOWER(p_user_id));
       -- Not sure why are you checking p_user_id is NULL
       loop
       fetch rc_emp_info into var1,var2,var3,var4,var5,var6;
       exit when rc_emp_info%notfound;
      -- here you do whatever you want with the variables
       end loop;
    end get_emp_info;