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
507 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
  • 2
4 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 250 total points
ID: 37752638
0
 
LVL 73

Expert Comment

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

Assisted Solution

by:sujith80
sujith80 earned 250 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 76

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

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

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…
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 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.
This video shows how to recover a database from a user managed backup

744 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

11 Experts available now in Live!

Get 1:1 Help Now