Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

how we can filter out a nested table? or how we can use where clause in nested table?

Posted on 2012-03-22
4
Medium Priority
?
521 Views
Last Modified: 2012-03-22
I have nested table like this

CREATE TABLE "MMS_STG1"."MMS_AUDIT"
   (      "AUDIT_ID" NUMBER,
      "TABLE_NAME" VARCHAR2(30),
      "DML_TYPE" VARCHAR2(30),
      "MODIFIED_USER" VARCHAR2(100),
      "TIMESTAMP" DATE,
      "CHANGE_HISTORY" "MMS_STG1"."TABLE_HISTORY_TAB" ,
       PRIMARY KEY ("AUDIT_ID")
   NESTED TABLE "CHANGE_HISTORY" STORE AS "HIST"

CREATE OR REPLACE TYPE "MMS_STG1"."TABLE_HISTORY_TAB" IS TABLE OF table_history;

CREATE OR REPLACE TYPE "MMS_STG1"."TABLE_HISTORY" AS OBJECT (
column_name varchar2(30),
new_value varchar2(4000),
old_value varchar2(4000)
);

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

I can select from MMS_AUDIT in plsql developer, which gives a column for collection.
 but how I can filter out the collection. Based on the conditions in collections, I wanted to retrieve the records in MMS_AUDIT.
0
Comment
Question by:sakthikumar
[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
  • 2
4 Comments
 
LVL 77

Accepted Solution

by:
slightwv (䄆 Netminder) earned 1000 total points
ID: 37752638
0
 
LVL 74

Expert Comment

by:sdstuber
ID: 37753042
please provide sample data and expected output
0
 
LVL 27

Assisted Solution

by:sujith80
sujith80 earned 1000 total points
ID: 37753209
See this example.I have used your objects as an exmaple.
You can use TABLE clause to un-nest the nested table.

SQL> insert into mms_audit
  2  values(
  3  100,
  4  'test1',
  5  TABLE_HISTORY_TAB(TABLE_HISTORY('col1', 'new1', 'old1'), TABLE_HISTORY('col2', 'new2', 'old2'))
  6  );

1 row created.

SQL>
SQL> insert into mms_audit
  2  values(
  3  200,
  4  'newtable',
  5  TABLE_HISTORY_TAB(TABLE_HISTORY('newcol', 'new1', 'old1'), TABLE_HISTORY('newcol2', 'new2', 'old2'))
  6  );

1 row created.

SQL>
SQL> select audit_id, table_name, column_name, new_value, old_value
  2  from mms_audit m, table(m.change_history);

  AUDIT_ID TABLE_NAME                     COLUMN_NAME                    NEW_VALUE  OLD_VALUE
---------- ------------------------------ ------------------------------ ---------- ----------
       100 test1                          col1                           new1       old1
       100 test1                          col2                           new2       old2
       200 newtable                       newcol                         new1       old1
       200 newtable                       newcol2                        new2       old2

SQL>
SQL> select audit_id, table_name, column_name, new_value, old_value
  2  from mms_audit m, table(m.change_history)
  3  where column_name = 'newcol1';

no rows selected

SQL> select audit_id, table_name, column_name, new_value, old_value
  2  from mms_audit m, table(m.change_history)
  3  where column_name = 'newcol';

  AUDIT_ID TABLE_NAME                     COLUMN_NAME                    NEW_VALUE  OLD_VALUE
---------- ------------------------------ ------------------------------ ---------- ----------
       200 newtable                       newcol                         new1       old1

Open in new window

0
 
LVL 77

Expert Comment

by:slightwv (䄆 Netminder)
ID: 37753238
>>You can use TABLE clause to un-nest the nested table.

Aside from using the names in the original post, isn't that basically the same as the example in the link I posted?
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

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

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…
Cursors in Oracle: A cursor is used to process individual rows returned by database system for a query. In oracle every SQL statement executed by the oracle server has a private area. This area contains information about the SQL statement and the…
This video explains at a high level with the mandatory Oracle Memory processes are as well as touching on some of the more common optional ones.
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.

610 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