Solved

Oracle Table Type Needs Multiple Rows

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

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 74

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 77

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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

Suggested Solutions

I remember the day when someone asked me to create a user for an application developement. The user should be able to create views and materialized views and, so, I used the following syntax: (CODE) This way, I guessed, I would ensure that use…
How to Unravel a Tricky Query Introduction If you browse through the Oracle zones or any of the other database-related zones you'll come across some complicated solutions and sometimes you'll just have to wonder how anyone came up with them.  …
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
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.

730 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