Wednesday, 15 May 2013

PL/SQL Nested TABLE THEORY

Please consider the following program which explains how to create Nested tables and the use of the Nested tables.

create or replace type emp_object as  object
(ID  VARCHAR2(50 BYTE),
NAME VARCHAR2(20 BYTE),
JOB  VARCHAR2(20 BYTE),
SALARY VARCHAR2(50 BYTE),
DEPARTMENT VARCHAR2(50 BYTE)
location varchar2(50));

create type dept1_type as table of dept1_object;

create type dept1_object as  object
(DEPT_ID  NUMBER,
DNAME  VARCHAR2(20 BYTE));

create table emp_dept
(id number,
 name varchar2(50),
  emp_dtls emp_type,
   dept_dtls dept1_type);
 
nested table emp_dtls store as emp_type_cs;
nested table dept_dtls store as dept1_type_cs;


insert into emp_dept values(2,'xyz',emp_type(emp_object('1002','Tiger','Programmer',' 20000','102')),dept1_type(dept1_object(30,'HR')));

ALTER TYPE emp_object ADD ATTRIBUTE (location varchar2(30)) CASCADE;

select * from the (select emp_dtls from emp_dept where id =1  );

No comments:

Post a Comment