-
Notifications
You must be signed in to change notification settings - Fork 0
/
oracle.sql
97 lines (75 loc) · 1.92 KB
/
oracle.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/**
* Author: Igor Morenko <morenko at lionsoft.ru>
* Created: Jun 7, 2017
*/
-- Drop
DROP TABLE companies;
DROP TYPE company_typ;
DROP TYPE department_list;
DROP TYPE department_typ;
DROP TYPE employee_list;
DROP TYPE employee_typ;
DROP TYPE address_typ;
-- Create
CREATE TYPE address_typ AS OBJECT (
"COUNTRY" VARCHAR2(200),
"CITY" VARCHAR2(200),
"STREET" VARCHAR2(200),
"HOUSE" VARCHAR2(200),
"OFFICE" VARCHAR2(200),
"ZIP" NUMBER(6)
);
/
CREATE TYPE employee_typ AS OBJECT (
"NUM" NUMBER,
"FIRST_NAME" VARCHAR2(200),
"LAST_NAME" VARCHAR2(200),
"JOB" VARCHAR2(200),
"SALARY" NUMBER
);
/
CREATE TYPE employee_list AS TABLE OF employee_typ;
/
CREATE TYPE department_typ AS OBJECT (
"ID" NUMBER,
"NAME" VARCHAR2(200),
"EMPLOYEES" EMPLOYEE_LIST
);
/
CREATE TYPE department_list AS TABLE OF department_typ;
/
CREATE TYPE company_typ AS OBJECT (
"INN" NUMBER,
"NAME" VARCHAR2(200),
"ADDRESS" ADDRESS_TYP,
"DEPARTMENTS" DEPARTMENT_LIST
);
/
CREATE TABLE companies OF company_typ
NESTED TABLE departments STORE AS department_tab (
NESTED TABLE employees STORE AS employee_tab
)
;
ALTER TABLE companies ADD CONSTRAINT companies_pk PRIMARY KEY (inn);
ALTER TABLE department_tab ADD CONSTRAINT departments_pk PRIMARY KEY (id);
ALTER TABLE employee_tab ADD CONSTRAINT employees_pk PRIMARY KEY (num);
-- Load
INSERT INTO companies
VALUES (
COMPANY_TYP(
1234567
, 'LionSoft LLC'
, ADDRESS_TYP('Russia', 'Tula', 'Lenina ave.', 102, 4, 300026)
, DEPARTMENT_LIST(
DEPARTMENT_TYP(
1
, 'Accounting'
, EMPLOYEE_LIST(
EMPLOYEE_TYP(1, 'Igor', 'Morenko', 'President', 5000),
EMPLOYEE_TYP(2, 'Alexander', 'Morenko', 'Manager', 3000)
)
)
)
)
);
COMMIT;