How to use an Oracle Ref Cursor from C# ODP.NET as a ReturnValue Parameter, without using a Stored Function or Procedure?

后端 未结 1 1700
长发绾君心
长发绾君心 2021-01-13 07:41

I need help understanding if the way I\'m trying to use a Ref Cursor as a ReturnValue Parameter for multiple records/values, with the PL/SQL just being the CommandText of an

相关标签:
1条回答
  • 2021-01-13 08:09

    I will try an answer instead of another comment.

    As I said in one comment, a pure/simple select-statement does not work in PL/SQL. But I was wrong in stating, that you need a stored function to return a ref cursor.

    But first things first: The type "id_array" you declare in your PL/SQL-block is a PL/SQL type. It cannot be used in a ref cursor select statement. Instead you will need a SQL type:

    create type id_array as table of number;
    

    This needs to be executed only once, just like a "create table".

    Your PL/SQL-block could then look like this:

    DECLARE
        t_ids   id_array;
    BEGIN
        UPDATE WorkerStatus
        SET
             StateId = :StateId
            ,StateReasonId = :StateReasonId
        WHERE
            StateId = :CurrentStateId
        RETURNING Id BULK COLLECT INTO t_Ids;
    
        OPEN :rcursor FOR SELECT * FROM TABLE(cast(t_Ids as id_array));    
    END;
    

    PS:
    While assembling this post, I realized where the ORA-00942 might come from. The array t_ids was based on a PL/SQL type, which is not known/available on the SQL side.

    0 讨论(0)
提交回复
热议问题