Solved

SELECT data from TABLE TYPE

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

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.

Join & Write a Comment

Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
How to Create User-Defined Aggregates in Oracle Before we begin creating these things, what are user-defined aggregates?  They are a feature introduced in Oracle 9i that allows a developer to create his or her own functions like "SUM", "AVG", and…
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 how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

705 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