Declaring a Nested Table in SQL
DROP TABLE sophomores CASCADE CONSTRAINTS PURGE;
DROP TYPE student;
DROP TYPE CourseList;
-------------------------------------------
CREATE TYPE CourseList AS TABLE OF VARCHAR2(10) -- define type
/
CREATE TYPE student AS OBJECT ( -- create object
id_num INTEGER(4),
name VARCHAR2(25),
address VARCHAR2(35),
status CHAR(2),
courses CourseList); -- declare nested table as attribute
/
CREATE TABLE sophomores of student
NESTED TABLE courses STORE AS courses_nt
/
OUTPUT:-
20:40:43 SQL> DROP TABLE sophomores CASCADE CONSTRAINTS PURGE;
Table dropped.
Elapsed: 00:00:00.04
20:40:44 SQL> DROP TYPE student;
Type dropped.
Elapsed: 00:00:00.09
20:40:44 SQL> DROP TYPE CourseList;
Type dropped.
Elapsed: 00:00:00.06
20:40:44 SQL> CREATE TYPE CourseList AS TABLE OF VARCHAR2(10) -- define type
20:40:44 2 /
Type created.
Elapsed: 00:00:00.01
20:40:44 SQL> CREATE TYPE student AS OBJECT ( -- create object
20:40:44 2 id_num INTEGER(4),
20:40:44 3 name VARCHAR2(25),
20:40:44 4 address VARCHAR2(35),
20:40:44 5 status CHAR(2),
20:40:44 6 courses CourseList); -- declare nested table as attribute
20:40:44 7 /
Type created.
Elapsed: 00:00:00.06
20:40:44 SQL> CREATE TABLE sophomores of student
20:40:44 2 NESTED TABLE courses STORE AS courses_nt
20:40:44 3 /
Table created.
Elapsed: 00:00:00.03
0 comments:
Post a Comment