Solved

SELECT data from TABLE TYPE

Posted on 2014-07-20
3
808 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
3 Comments
 

Author Comment

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

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
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…
Via a live example show how to connect to RMAN, make basic configuration settings changes and then take a backup of a demo database
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…

867 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

22 Experts available now in Live!

Get 1:1 Help Now