?
Solved

SELECT data from TABLE TYPE

Posted on 2014-07-20
3
Medium Priority
?
1,065 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 2000 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
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.
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…
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…

762 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