Solved

Oracle Table Type Needs Multiple Rows

Posted on 2011-09-27
4
270 Views
Last Modified: 2012-05-12
I have a type and a table of that type
type INV_TABLE is the table
type INV_TYPE is the type

Why cant I insert multiple rows into the table.
It only ever outputs one row with  select * from table(GET_INVENTORY(97));

create or replace
function get_inventory(in_var in number) return INV_TABLE is
      
   test_recs  INV_TABLE;
    
    begin
     
  SELECT  INV_TYPE( 1, 'A',  2,  'B' )
    BULK     COLLECT
    INTO     test_recs
    FROM    dual;
       
     --only this is seen with test:
    SELECT  INV_TYPE( 1, 'A',  2,  'C' )
    BULK     COLLECT
    INTO     test_recs
    FROM    dual;
    
-- insert into test_recs values( 1, 'A',  2, 'B' ); --does not work. why?
 
    RETURN test_recs; 
 
    end;

Open in new window

0
Comment
Question by:claghorn
  • 2
4 Comments
 
LVL 73

Assisted Solution

by:sdstuber
sdstuber earned 334 total points
ID: 36710394
CREATE OR REPLACE FUNCTION get_inventory(in_var IN NUMBER)
    RETURN inv_table
IS
    test_recs   inv_table;
BEGIN
    SELECT t
      BULK COLLECT INTO test_recs
      FROM (SELECT inv_type(1, 'A', 2, 'B') t FROM DUAL
            UNION ALL
            SELECT inv_type(1, 'A', 2, 'C') FROM DUAL);


    RETURN test_recs;
END;
0
 
LVL 73

Accepted Solution

by:
sdstuber earned 334 total points
ID: 36710405
you also might want to consider using a pipelined function

CREATE OR REPLACE FUNCTION get_inventory(in_var IN NUMBER)
    RETURN inv_table
    PIPELINED
IS
BEGIN
    PIPE ROW (inv_type(1, 'A', 2, 'B'));
    PIPE ROW (inv_type(1, 'A', 2, 'C'));

    RETURN;
END;
0
 
LVL 76

Assisted Solution

by:slightwv (䄆 Netminder)
slightwv (䄆 Netminder) earned 166 total points
ID: 36710407
>>--does not work. why?


PL/SQL tables are not the same as physical Oracle Tables.  You would need to EXTEND them and manually assign the values.
0
 

Author Closing Comment

by:claghorn
ID: 36711848
Thanks. I'll target these methods in my readings.
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

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

Suggested Solutions

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
From implementing a password expiration date, to datatype conversions and file export options, these are some useful settings I've found in Jasper Server.
This video shows syntax for various backup options while discussing how the different basic backup types work.  It explains how to take full backups, incremental level 0 backups, incremental level 1 backups in both differential and cumulative mode a…
This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

910 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now