From Stored Procedure, return OUT parameter & OUT cursor & parse result (Oracle)

前端 未结 5 2109
走了就别回头了
走了就别回头了 2021-01-01 02:36

Question : Is it possible to return using OUT :

Both : A variable & A cursor, from my code below ??


I saw a similar question for SqlDB but after

5条回答
  •  佛祖请我去吃肉
    2021-01-01 03:00

    One could consider an alternative to the repeated query in your procedure. For example:

    CREATE OR REPLACE
    PROCEDURE SPGETRESULTANDSETFLAG
    (
     pFilter VARCHAR2,
     pTableID RAW,
     myCursor OUT types.cursorType
    )
    AS
      DataQuery VARCHAR(20000) := '';
    BEGIN
      DataQuery := 'SELECT COUNT(*) OVER () AS TheCount, T.* FROM '
                    || F_GET_TABLENAME_FROM_ID(PTABLEID => pTableID) 
                    || ' AS T WHERE ' || pFilter; 
      --Get the Return Cursor
      Open myCursor for DataQuery;
    
    END SPGETRESULTANDSETFLAG;
    

    In this way you don't have to query the table twice, you have the count in each row of your resultset. You can get rid of your parameters dealing with the max rowcount as well, and check the count value in your calling routine by fetching one row.

    Just an alternative thought...

提交回复
热议问题