zoukankan      html  css  js  c++  java
  • ORACLE之PACKAGE-游标变量

    刚学pl/sql编程,写了两个package。pkg_temp_fn31和pkg_temp_fn32。内容涉及pl/sql基本语法,游标变量,存储过程(in,out)。

      pkg_temp_fn31调用pkg_temp_fn32,pkg_temp_fn32中定义了out游标变量。

    • pkg_temp_fn31内有一个procedure test(p_mapid number)

      创建包规范

    1 create or replace package pkg_temp_fn31 is
    2   --25-03-2016 
    3   procedure test(p_mapid number);
    4 end pkg_temp_fn31;
    5 --exec pkg_temp_fn31.test(&p_mapid);执行此包

      创建包体pkg_temp_fn31

    create or replace package body pkg_temp_fn31
    is
     procedure test(p_mapid number) is
      p_cursor pkg_temp_fn32.ref_cursor;--
      p_personno t_fn_person.person_code%type;
      p_personname t_fn_person.person_name%type;
      begin
        pkg_temp_fn32.queryall(p_mapid,p_cursor);--
        loop
          fetch p_cursor into p_personno,p_personname;
          exit when p_cursor%notfound;
          dbms_output.put_line(p_personno||'''s person name is '||p_personname);  
        end loop;   
      end test;
    end pkg_temp_fn31;
    • kg_temp_fn32内有一个procedure queryall(pmap_id number ,p_cursor out ref_cursor)

      创建包规范  

    1 create or replace package pkg_temp_fn32 is
    2 --25/03/2016
    3   type ref_cursor is ref cursor;--
    4   procedure queryall(pmap_id number ,p_cursor out ref_cursor);
    5 end pkg_temp_fn32;

      创建包体pkg_temp_fn32

    create or replace package body pkg_temp_fn32 is
    procedure queryall(pmap_id number ,p_cursor out ref_cursor)
      is
      RF pkg_temp_fn32.ref_cursor;
      begin
        open RF for
          select x.person_code,x.person_name from t_fn_person x
                   where x.map_id=pmap_id;
        p_cursor:=RF;
      end queryall;
    end pkg_temp_fn32;

    执行结果:

    命令窗口:

     一般sql窗口:

    -- 调用过程
    call pkg_temp_fn31.test('000001')

  • 相关阅读:
    poj 3126 Prime Path
    poj 2255 Tree Recovery
    spoj 7259 LITE
    poj 1742 Coins
    poj 1915 Knight Moves
    poj 2352 Stars
    【祝贺】gooogleman嵌入式开发板联盟图标设计完成,Let me Show!
    【讨论】TE6410/OK6410 开发板dnw c0008000是什么意思, ?
    【讨论】为什么我的300W摄像头偶尔会拍照不成功?
    【探讨】关于2440 触摸屏驱动的怪异现象分析
  • 原文地址:https://www.cnblogs.com/hoaprox/p/5318836.html
Copyright © 2011-2022 走看看