Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Nested table @ schema level - how to pull first subscript?

Mac_Freak_RahulAug 3 2015 — edited Aug 3 2015

Hi,

My oracle database version : 11g

I am presenting the code here and these are the steps through which I created a table and within that theres a regular column with number but the 2nd column is a nested table.

1) create or replace type s_def_NT_DepEmployees is table of  varchar2(100);

2) 

create table employees_NT_test

( department_id number

    , c_of_s_def_NT_DepEmployees s_def_NT_DepEmployees)

nested table c_of_s_def_NT_DepEmployees store as NTs_c_of_s_def_NT_DepEmployees

3) Now I have inserted 2 records:

insert into employees_NT_test values(1,s_def_NT_DepEmployees('Rahul','Myra'));

insert into employees_NT_test values(2,s_def_NT_DepEmployees('Rashi','Gaurav'));

4) Now firing this sql gives me employees of department_id : 1

select column_value

from table(select c_of_s_def_NT_DepEmployees from employees_NT_test where department_id = 1);

Output:

Rahul

Myra

Now my question : I just want to select the first subscript : ie: rahul(and not myra ) and it should be consistent such that if I select both departments I should get my output as:

Department_id | employees

1                    | Rahul

2                    | Rashi

PS: I am looking for an sql query, I hope I have presented my question clearly, if there are any doubts please let me know.

Thanks in advance

Rahul

This post has been answered by odie_63 on Aug 3 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 31 2015
Added on Aug 3 2015
10 comments
452 views