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
Solved

SELECT data from TABLE TYPE

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

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.

Question has a verified solution.

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

Working with Network Access Control Lists in Oracle 11g (part 1) Part 2: http://www.e-e.com/A_9074.html So, you upgraded to a shiny new 11g database and all of a sudden every program that used UTL_MAIL, UTL_SMTP, UTL_TCP, UTL_HTTP or any oth…
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…
This video shows how to copy a database user from one database to another user DBMS_METADATA.  It also shows how to copy a user's permissions and discusses password hash differences between Oracle 10g and 11g.
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…

837 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