Solved

SELECT data from TABLE TYPE

Posted on 2014-07-20
3
963 Views
Last Modified: 2014-07-21
HI, i have,

CREATE OR REPLACE TYPE t1_type
    FORCE AS OBJECT
(
    code NUMBER(15),
    description VARCHAR2(15)
);

create or replace TYPE T1_TYPE_TABLE FORCE
AS
  TABLE OF T1_TYPE;

CREATE OR REPLACE TYPE t2_type
    FORCE AS OBJECT
(
    id NUMBER(15),
    name VARCHAR2(15),
    address VARCHAR2(15),
    T1_TAB  T1_TYPE_TABLE
    );


create or replace TYPE T2_TYPE_TABLE FORCE
AS
  TABLE OF T2_TYPE;


How to we use SELECT in multi-type table objects:
I want to query data from T1_TYPE_TABLE  where CODE = 2
And I also want to query the data from T2_TYPE_TABLE  where ID = 4;



THANKS AND REGARDS,
0
Comment
Question by:Sudees
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 

Author Comment

by:Sudees
ID: 40207980
I am asking about using SELECT query not using FOR LOOP
0
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 500 total points
ID: 40207989
You 'can' by casting the PL/SQL table as a regular table but I would not suggest using this method.  You are taking an in-memory table switching context from pl/sql into regular SQL, creating a cursor to select from then switching back to PL/SQL.

Not very efficient in my opinion.

That said, here's the code based from the code in the previous question.

CREATE OR REPLACE TYPE r_type
    FORCE AS OBJECT
(
    code NUMBER(15),
    description VARCHAR2(15)
);
/


CREATE OR REPLACE TYPE tr_type IS TABLE OF r_type;
/


CREATE OR REPLACE PROCEDURE t1
AS

    tr_type_i tr_type := tr_type();
    i         INTEGER;
    junk      NUMBER;
BEGIN
    tr_type_i.EXTEND(3);
    tr_type_i(1) := r_type(NULL, NULL);
    tr_type_i(1).code := 1;
    tr_type_i(1).description := 't1';

    tr_type_i(2) := r_type(NULL, NULL);
    tr_type_i(2).code := 2;
    tr_type_i(2).description := 't1';

    tr_type_i(3) := r_type(NULL, NULL);
    tr_type_i(3).code := 4;
    tr_type_i(3).description := 't1';




	SELECT count(*) into junk
	FROM
	TABLE(CAST(tr_type_i AS tr_type))
	WHERE code=4;

	if junk>0 then
        	DBMS_OUTPUT.put_line('Found an object in the collection with code=4');
	else
        	DBMS_OUTPUT.put_line('No code=4 found');
	end if;
END;
/
                                          
show errors

exec t1;

Open in new window

0

Featured Post

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

Question has a verified solution.

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

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…
Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
Via a live example, show how to take different types of Oracle backups using RMAN.

688 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