Solved

Oracle Table Type Needs Multiple Rows

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

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Oracle SQL 6 73
Help on model clause 5 37
Sybase and replication server 13 39
Oracle 12c Default Isolation Level 17 41
Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
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 setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…

828 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