【问题标题】:Pl/SQL Procedure CURSOR For LoopPl/SQL 过程 CURSOR For 循环
【发布时间】:2014-06-19 09:20:17
【问题描述】:

我是 PL/SQL 的新手,正在尝试使用 CURSOR。我想验证一个插入过程,所以我写了另一个过程来这样做。

CREATE OR REPLACE PROCEDURE verify_insert

IS

   CURSOR map_cur IS

      SELECT Page_ID_NBR, Page_Type, Page_Dcpn FROM SSC_Page_Map;

      map_rec map_cur%ROWTYPE;

BEGIN

   OPEN map_cur;

   FOR map_rec in map_cur

   LOOP

      DBMS_OUTPUT.PUT_LINE('ID: ' || map_cur.Page_ID_NBR || ' ' || 'Type' ||  map_cur.Page_Type || ' ' || 'Description' || map_cur.Page_Dcpn);   

   END LOOP;

   CLOSE map_cur;

END;

SHOW ERRORS PROCEDURE verify_insert;

我收到以下消息

[Warning] ORA-24344: success with compilation error
19/44   PLS-00225: subprogram or cursor 'MAP_CUR' reference is out of scope
19/5    PL/SQL: Statement ignored
(47: 0): Warning: compiled but with compilation errors

我也看到了

Errors for PROCEDURE VERIFY_INSERT

LINE/COL ERROR                                                            
-------- -----------------------------------------------------------------
19/44    PLS-00225: subprogram or cursor 'MAP_CUR' reference is out of sco


19/5     PL/SQL: Statement ignored                                        

正如我所写的,我是新手,正在尝试从Oracle PL/SQL Programming (Feuerstein) 和网络拼凑 PL/SQL 知识。走到一起,但没有我想要的那么快。

【问题讨论】:

    标签: plsql oracle11g toad


    【解决方案1】:

    您的循环正在从游标中提取一行到记录类型中。在循环内部,您需要从记录类型中读取数据。在您的dbms_output.put_line 调用中,您希望引用记录而不是光标。

    DBMS_OUTPUT.PUT_LINE('ID: ' || map_rec.Page_ID_NBR || 
                  ' ' || 'Type' || map_rec.Page_Type || 
                  ' ' || 'Description' || map_rec.Page_Dcpn);  
    

    【讨论】:

    • 谢谢。我只是从网上复制不好的例子。能否请您指出一个很棒的网站,在那里我可以快速增加我的知识并避免有其陷阱的狩猎和啄食方法?谢谢。
    猜你喜欢
    • 1970-01-01
    • 2011-04-22
    • 2017-07-30
    • 1970-01-01
    • 1970-01-01
    • 2021-07-07
    • 2013-07-21
    • 2013-03-29
    • 2019-04-06
    相关资源
    最近更新 更多