Oracle Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsDatabasesOracle Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 5th, 2004, 01:41 AM
KSB KSB is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 53 KSB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 40 m 7 sec
Reputation Power: 4
Unhappy Retreiving rows from a table which is returned by a function.

Hai,

I have Peculiar problem, I have written a function in a package which returns table of record. But i am unable to retreive them. Is there any problem with the function ,if no how to get the data show it with a simple select statement not with <tablename>.<colname> inside a procedure.

Any help.....

Code:
create or replace package GetNextSet1 as

   type sName is  table of student.stuname%type  index by binary_integer;
   
   type srno is   table of student.rno%type   index by binary_integer;

   type t_objtab is table of student%rowtype index by binary_integer;
   
   procedure CloseCursor;
   
   procedure OpenCursor;

   procedure SetRows (pRows pls_integer);

   function RetrieveRows (pRows   pls_integer := null) return t_objtab;
   
end GetNextSet1;
/


-----------------------------------------------------------------------------------------------------


create or replace package body GetNextSet1 as
   
   vName sName;
   vrno  srno;
   vTable t_objtab;
   
   vRowsDefault   pls_integer := 3;
   vRows          pls_integer;
  
       
   cursor csrEmployees is
   select rno,stuname
   from student;
      
   /* Display retrieved rows */
   procedure ShowBatch
   is
   begin
   
      if (vName.count > 0)
      then
      
         for nIndex in 1..vName.count
         loop
            
            dbms_output.put_line(rpad(vName(nIndex), 20) ||
                                 lpad(to_char(vrno(nIndex)), 5));
            
         end loop;
             
      end if;
   
   end ShowBatch;
   
   /* Reset variables and collections */
   procedure Reset
   is
   begin
   
      vName.delete;
              
      vRows   := vRowsDefault;
   
   end Reset;
   
   /* Close cursor */
   procedure CloseCursor
   is
   begin
      
      if csrEmployees%isopen
      then
         close csrEmployees;
         
         Reset;
      end if;
      
   end CloseCursor;
   
   /* Open cursor */
   procedure OpenCursor
   is
   begin
   
      CloseCursor;      
         
      open csrEmployees;

   end OpenCursor;

   /* Retrieve rows from the cursor in chunks of pRows.
      If the cursor is not open, open it for the salary
      value of pSalary
   */
   function RetrieveRows (pRows   pls_integer := null) return t_objtab
   is
   begin
   
     if not csrEmployees%isopen
     then
             
   dbms_output.put_line('Opening the cursor.');
        OpenCursor;
   end if;
   
   if (nvl(pRows, 0) > 0)
        then
           vRows := pRows;
        else
           vRows := vRowsDefault;
        end if;
     
     fetch csrEmployees bulk collect into vTable limit vRows;
     
     --ShowBatch;

     
     if csrEmployees%notfound
     then
     
        dbms_output.put_line('All rows retrieved. Closing the cursor.');
        CloseCursor;
     
     end if;

     return vTable;
        
   end RetrieveRows;

    /* Set the default value of rows */
   procedure SetRows (pRows pls_integer)
   is
   begin
      
      if (nvl(pRows, 0) > 0)
      then
         
         vRowsDefault := pRows;
         
      end if;
      
   end SetRows;
   
begin
   
   /* Initialization */
   vRows   := vRowsDefault;
   
end GetNextSet1;
/



---------
Executing
---------

declare t getnextset1.t_objtab;
begin
   t :=getnextset1.RetrieveRows();
end;


Thanks in advance

Reply With Quote
  #2  
Old November 7th, 2004, 06:21 PM
ProggerPete ProggerPete is offline
Contributing User
Dev Shed Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Brisbane, Australia
Posts: 1,438 ProggerPete User rank is Sergeant (500 - 2000 Reputation Level)ProggerPete User rank is Sergeant (500 - 2000 Reputation Level)ProggerPete User rank is Sergeant (500 - 2000 Reputation Level)ProggerPete User rank is Sergeant (500 - 2000 Reputation Level)ProggerPete User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Week 1 Day 1 h 16 m 25 sec
Reputation Power: 23
I'm no oracle function guru so I'm not going to get keen on looking at your code. However I do use a function I flogged from someone on the web that turns a comma delimited string into a table. In order to get the rows out of it I have to tell oracle that the function has returned a table.

Here's how I get the info

select * from TABLE(convert_string('1,2,3'))
__________________
Like the answers I give? Why not ask me directly at my forum. I'm always glad to help.

Javascript scripts and tips can be found at Dynamic Tools.
Check out DynamicTable, the best javascript table sorter around.
Get reliable and affordable hosting at www.thinksmarthosting.com

Reply With Quote
  #3  
Old November 8th, 2004, 01:29 AM
KSB KSB is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Oct 2004
Posts: 53 KSB User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 12 h 40 m 7 sec
Reputation Power: 4
Thanks for the suggestion.

But it may not help me. Bcoz, the data i fetch is large, contains CLOB types and thousand of records each of 60 columns. Is there any other way.

Any other suggestions Please....

Reply With Quote
Reply

Viewing: Dev Shed ForumsDatabasesOracle Development > Retreiving rows from a table which is returned by a function.


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway
Stay green...Green IT