獲取Oracle過程當中的OUT SYS_REFCURSOR值

 一個項目中的實例:獲取Oracle過程當中的返回SYS_REFCURSOR。注意:若是SYS_REFCURSOR爲一個表或視圖。能夠經過表名%ROWTYPE獲取每行數據,而沒必要另外定義type。測試

原過程大體以下:spa

 1 PROCEDURE P_USER_LOGIN(P_USERLOGINID IN VARCHAR2,P_PASSWORD IN VARCHAR2,P_SHOPID IN VARCHAR2,P_CURSOR OUT SYS_REFCURSOR) AS
 2    ----.......
 3 
 4 OPEN P_CURSOR FOR
 5          SELECT r_UserList.Userid           AS USERID,
 6                 r_UserList.Userloginid      AS USERLOGINID,
 7                 r_UserList.Username         AS USERNAME,
 8                 r_UserList.Usertype         AS USERTYPE,
 9                 r_UserList.Isposer          AS Isposer,
10                 r_UserShopRole.Posroleid    AS Posroleid,
11                 r_UserShopRole.Roleid       AS ROLEID,
12                 r_RoleList.Rolename         AS ROLENAME,
13                 l_Info                      AS INFO
14            FROM dual;

15 ----.......

 

 

測試:code

/*
--如下爲檢測登陸的demo語句
declare
  type_cur SYS_REFCURSOR;
  -- T_ROW type_cur%ROWTYPE;
  type Type_ROW  is record(
  USERID      nvarchar2(30),
  USERLOGINID nvarchar2(30),
  USERNAME    nvarchar2(30),
  USERTYPE    nvarchar2(20),
  Isposer     nvarchar2(10),
  Posroleid   nvarchar2(10),
  ROLEID      nvarchar2(10),
  ROLENAME    nvarchar2(30),
  INFO        nvarchar2(500)
  );
  T_Row Type_ROW;
 
    
begin

DBUSRMCC.LOGIN_MANAGER.P_USER_LOGIN('235',
                             '0201F1233',
                             'A00001',
                             type_cur);
 LOOP  
    FETCH type_cur  INTO T_ROW;  
    EXIT WHEN type_cur%NOTFOUND;  
    DBMS_OUTPUT.PUT_LINE(T_ROW.USERLOGINID||':'||T_ROW.INFO );  
   
  END LOOP;  
  CLOSE type_cur;  ----必需要明確的關閉遊標  
end;
相關文章
相關標籤/搜索