how to access an Oracle procedure's OUT parameter when calling it?

走远了吗. 提交于 2019-12-24 11:22:15

问题


If I write a simple function doSomething, I can get its result by executing :

select doSomething() from dual;

But, if I wish to call a procedure that has an OUT cursor being passed to it (along with another int parameter), how do I call that procedure inside a query and access the result of the cursor ?

Calling it inside a query is not compulsory.. its just that I want to access the results of that procedure


回答1:


You can create a procedure like

    CREATE OR REPLACE PROCEDURE your_procedure(out_cursor OUT sys_refcursor)
    IS
    BEGIN
        OPEN out_cursor FOR
            SELECT  employee_name
              FROM  employees;

    END;
    /

Once you create your procedure wrap the procedure in a function which returns a cursor like the following

CREATE OR REPLACE FUNCTION your_function
    RETURN sys_refcursor
AS
    o_param  sys_refcursor;
BEGIN
    o_param := NULL;
    your_procedure(o_param);
    RETURN o_param;
EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
        -- raise                                  

    WHEN OTHERS
    THEN
        -- raise
END your_function;
/

To see the results from sql do as

select your_function from dual;

Update 1

To see result in SQL Developer

Step 1

Double click on your results in SQL Developer

[Results][1]

Step 2 Single Click on the button with dots. That will pop up the values

[Grid][2]




回答2:


You can Do Something Like This

select doSomething(cursor (select int_col from your_table)) colname from dual

Hope this Help



来源:https://stackoverflow.com/questions/13339899/how-to-access-an-oracle-procedures-out-parameter-when-calling-it

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!