Solved

Oracle Table Type Needs Multiple Rows

Posted on 2011-09-27
4
271 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

Title # Comments Views Activity
dates - loop 12 66
Oracle - SQL Where clause causing Invalid Number Error 4 33
SQL query question 8 73
Problem with duplicate records in Oracle query 16 26
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…
Checking the Alert Log in AWS RDS Oracle can be a pain through their user interface.  I made a script to download the Alert Log, look for errors, and email me the trace files.  In this article I'll describe what I did and share my script.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
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…

776 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