Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3338354

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T00:21:55+00:00 2026-05-18T00:21:55+00:00

I have an existing stored procedure that takes 2 parameters and returns back an

  • 0

I have an existing stored procedure that takes 2 parameters and returns back an oracle cursor. The cursor contains about 30 to 60 rows of data.

I want to use the above pre-existing stored procedure in another stored procedure as a table…basically I want to call the pre-existing stored procedure and see if the rows returned back contain a particular value.

For example:

SP 1 = get_data_1 (returns oracle cursor)
SP 2 = get_data_2 

in get_data_2

select count(*) from get_data_1 (pass_input_parms) A where A.ID = '12345'

Conceptually it seems like a trivial thing to do to me however, being new to the oracle world I do not know how to make use of preexisting stored procedures that return cursors.

How would I do this?

  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-18T00:21:56+00:00Added an answer on May 18, 2026 at 12:21 am

    You cannot reuse a REF CURSOR from get_data_1 in a subsequent SQL statement because it’s just a pointer to a statement handle. The cursor itself contains no data.

    You could do something like

    CREATE PROCEDURE get_data_2( p_cnt OUT NUMBER )
    AS
      l_rc  <<your cursor type>>;
      l_rec <<the type your cursor returns>>;
    BEGIN
      get_data_1(<<parameter 1>>, <<parameter 2>>, l_rc);
      p_cnt := 0;
      LOOP
        FETCH l_rc INTO l_rec;
        EXIT WHEN l_rc%NOTFOUND;
    
        IF( l_rec.id = '12345' )
        THEN
          p_cnt := p_cnt + 1;
        END IF;
      END LOOP;
      CLOSE l_rc;
    END;
    

    As you might imagine, though, this tends to get old relatively quickly. Given that, it tends not to be common in Oracle to have stored procedures that return REF CURSOR parameters except in cases where you are returning a finished view of the data to a client application. If there was a shared view, for example, that both GET_DATA_1 and GET_DATA_2 could query rather than having GET_DATA_2 call GET_DATA_1, that would simplify the program. If GET_DATA_1 was a pipelined table function rather than a procedure that returned a REF CURSOR, then it would be much easier to call GET_DATA_1 from GET_DATA_2.

    If you want to get started with pipelined table functions (using the SCOTT schema)

    create or replace type emp_obj as object (
      empno number,
      ename varchar2(10),
      job   varchar2(9),
      mgr   number,
      hiredate date );
    /
    
    create type emp_tbl
    as
    table of emp_obj;
    /
    
    create function emp_pipe( p_deptno IN NUMBER )
      return emp_tbl pipelined
    is
    begin
      FOR x IN (SELECT * FROM emp WHERE deptno = p_deptno)
      LOOP
        PIPE ROW( emp_obj( x.empno,
                           x.ename,
                           x.job,
                           x.mgr,
                           x.hiredate ) );
      END LOOP;
    END;
    /
    
    SQL> select * from table( emp_pipe( 10 ) );
    
         EMPNO ENAME      JOB              MGR HIREDATE
    ---------- ---------- --------- ---------- ---------
          7782 CLARK      MANAGER         7839 09-JUN-81
          7839 KING       PRESIDENT            17-NOV-81
          7934 MILLER     CLERK           7782 23-JAN-82
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a stored procedure that takes a comma-delimited string of IDs. I split
I have an existing SQL 2005 stored procedure that for some reason, outputs its
I have a stored procedure that finds all the existing databases and reads from
I have a stored procedure that is required to update an existing record with
For whatever reason, I have a lot of clients that have existing data that's
I want to write a stored procedure that queries XML files after I have
I want to execute stored procedure with one parameter that returns table using EF4
I am new to Transact SQL programming. I have created a stored procedure that
I have an existing ASP.NET 2.0 website, stored in Team Foundation Server 2005. Some
We have an existing WCF service that makes use of wsDualHttpBinding to enable callbacks

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.