Get resultset from oracle stored procedure

前端 未结 7 2335
生来不讨喜
生来不讨喜 2020-11-27 13:38

I\'m working on converting a stored procedure from SQL server to Oracle. This stored procedure provides a direct resultset. I mean that if you call the stored procedure in

7条回答
  •  庸人自扰
    2020-11-27 14:06

    FYI as of Oracle 12c, you can do this:

    CREATE OR REPLACE PROCEDURE testproc(n number)
    AS
      cur SYS_REFCURSOR;
    BEGIN
        OPEN cur FOR SELECT object_id,object_name from all_objects where rownum < n;
        DBMS_SQL.RETURN_RESULT(cur);
    END;
    /
    
    EXEC testproc(3);
    
    OBJECT_ID OBJECT_NAME                                                                                                                     
    ---------- ------------
    100 ORA$BASE                                                                                                                        
    116 DUAL                                                                                                                            
    

    This was supposed to get closer to other databases, and ease migrations. But it's not perfect to me, for instance SQL developer won't display it nicely as a normal SELECT.

    I prefer the output of pipeline functions, but they need more boilerplate to code.

    more info: https://oracle-base.com/articles/12c/implicit-statement-results-12cr1

提交回复
热议问题