?
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
?
524 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 78

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 78

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

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

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 2) Part 1: http://www.e-e.com/A_8429.html Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
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 about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
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…
Suggested Courses

850 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