1. The document defines several object types in Oracle SQL including state, contact_detail, address, staff, dept, and uses them to create tables with nested tables to store employee data with addresses and contact details.
2. Sample data is inserted into the dpt_reference table with nested tables of staff objects.
3. Queries are written to retrieve various data from the tables like getting staff IDs and department names, counting employees by department, finding department name for a staff, displaying department reports, and getting an employee's age and birthdate.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
75 views6 pages
Practical 2
1. The document defines several object types in Oracle SQL including state, contact_detail, address, staff, dept, and uses them to create tables with nested tables to store employee data with addresses and contact details.
2. Sample data is inserted into the dpt_reference table with nested tables of staff objects.
3. Queries are written to retrieve various data from the tables like getting staff IDs and department names, counting employees by department, finding department name for a staff, displaying department reports, and getting an employee's age and birthdate.
Type created. SQL> create or replace type contact_detail61 as object 2 ( 3 residence_no number(10), 4 office_no number(10), 5 email varchar2(30), 6 fax number(10), 7 mobile number(10) 8 ) 9 /
Type created.
SQL> create or replace type address61 as object 2 ( 3 road_no varchar2(7), 4 road_name varchar2(40), 5 landmark varchar2(40), 6 state state61, 7 contact contact_detail61 8* ) 9 /
Type created.
SQL> create or replace type staff61 as object( 2 staff_id number(6), 3 staff_name varchar2(40), 4 staff_address address61, 5 staff_deptno number(3), 6 staff_sal number(6), 7 staff_other varchar2(40), 8 dob date, 9 member function getAge return number) 10 /
Type created.
SQL> create or replace type body staff61 as member function getAge return number as 2 begin 3 return trunc(months_between(sysdate,dob)/12); 4 end getAge; 5 end; 6 /
Type body created.
SQL> create or replace type staffTableType as table of staff61 2 /
Type created.
SQL> create or replace type dept61 as object 2 ( 3 dept_id number(3), 4 location varchar2(30), 5 dept_name varchar2(20), 6 emp staffTableType 7 ) 8 /
Type created.
SQL> create table dpt_refernce of dept61 nested table emp store as NTrelation 2 /
SQL> select p.dept_id,p.dept_name,count(q.staff_id) as number_of_employees from dpt_refernce p,table (p.emp) q where p.dept_name='Purchase' group by dept_id,dept_name;