Solved

create a cursor for a record pl/sql

Posted on 2012-04-10
4
423 Views
Last Modified: 2012-04-10
I am trying to write a wrapper code around a number of procedures that return a record as a data type, the wrapper needs to be able to return the record as a cursor


example

declare
TYPE l_REC1 IS RECORD
    (  TODAY_DATE DATE
    ,  number_col   NUMBER(9)
    ,  varchar2_col  VARCHAR2(30) );

l_sqlstr      VARCHAR2(32000) ;

l_REC          l_REC1;
l_cur_1       sys_refcursor;
l_cur_2       sys_refcursor;

begin
 l_sqlstr :=
      ' select   sysdate today_date, 12345 number_col , ''ABC'' varchar2_col
        from    from dual';

l_REC := NULL;  

OPEN l_cur_1 FOR l_sqlstr;
     loop
        FETCH l_cur_1INTO l_REC;
        EXIT WHEN  l_cur_%notfound;
    end loop;
CLOSE  l_cur_1;

-- at this point i have the data in l_REC
--but how do i do the reverse, assmume i have a l_REC data populated
--how do i create a sys_refcursor for the data in l_REC?

OPEN l_cur_2 for l_REC;

End;

I would really return just the cursor l_cur_2, but hwo do i do that?
0
Comment
Question by:jhacharya
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
4 Comments
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 37829672
You cannot select from a record and turn it into a cursor.

Just open the curslt and return it:
OPEN l_cur_1 FOR l_sqlstr;

RETURN l_cur_1;
0
 
LVL 2

Author Comment

by:jhacharya
ID: 37829841
here is the problem with the solution you have propsed there are a number of functions that are already written in our application that really do the first part of returning a record ...

But now I am trying to create a wrapper around those function to retrun a cursor, becasue I need to pass a cursor to a vb program. I could look at re-writing the entire application, but I was looking for a way around the problem

If this cant be done then at least that one door that is shut
0
 
LVL 2

Author Comment

by:jhacharya
ID: 37829862
actually i have a work aournd, I am creating a different level of packages to just retrun the cursors, and this package is either called by the pl/sql program to return a record, or the vb program to return the cursor ...

it is a change but it should be fairly strait forward ...
0
 
LVL 2

Author Closing Comment

by:jhacharya
ID: 37829865
stopped me going down a path that was futile
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
Truncate is a DDL Command where as Delete is a DML Command. Both will delete data from table, but what is the difference between these below statements truncate table <table_name> ?? delete from <table_name> ?? The first command cannot be …
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.

696 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question