Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Spearing
authored and
Spearing
committed
Oct 5, 2016
0 parents
commit 6a95a6b
Showing
26 changed files
with
6,150 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,177 @@ | ||
connect system/manager@ORCL; | ||
create user plsql9i identified by plsql9i; | ||
grant connect,resource,dba to plsql9i; | ||
|
||
connect plsql9i/plsql9i@ORCL; | ||
|
||
CREATE TABLE items_tab (item_code varchar2(6) PRIMARY KEY, | ||
item_descr varchar2(20) NOT NULL); | ||
|
||
CREATE TABLE employee_test | ||
(empid number(10) PRIMARY KEY, | ||
lastname varchar2(30) NOT NULL, | ||
firstname varchar2(30) NOT NULL, | ||
middle_initial varchar2(2)); | ||
|
||
begin | ||
insert into employee_test values (101,'SMITH','JOHN',null); | ||
insert into employee_test values (102,'JOHNSON','ROBERT','L'); | ||
insert into employee_test values (103,'LAKSHMAN','BULUSU',null); | ||
insert into employee_test values (104,'KNOP','VICTORIA','A'); | ||
commit; | ||
end; | ||
/ | ||
|
||
-- Organizational Hierarchy System | ||
create table site_tab | ||
(site_no number(4) not null, | ||
site_descr varchar2(20) not null); | ||
|
||
alter table site_tab add primary key (site_no); | ||
|
||
create table hrc_tab | ||
(hrc_code number(4) not null, | ||
hrc_descr varchar2(20) not null); | ||
|
||
alter table hrc_tab add primary key (hrc_code); | ||
|
||
create table org_tab | ||
(hrc_code number(4) not null, | ||
org_id NUMBER(8) not null, | ||
org_short_name varchar2(30) not null, | ||
org_long_name varchar2(60)); | ||
|
||
alter table org_tab add sprimary key (hrc_code,org_id); | ||
alter table org_tab add constraint org_tab_uk unique (org_id); | ||
alter table org_tab | ||
add constraint org_tab_fk foreign key (hrc_code)references hrc_tab(hrc_code); | ||
|
||
create table org_site_tab | ||
(org_id number(8) not null, | ||
site_no number(4) not null ); | ||
|
||
alter table org_site_tab add primary key (org_id,site_no); | ||
alter table org_site_tab | ||
add constraint org_site_tab_fk1 foreign key (org_id)references org_tab(org_id); | ||
alter table org_site_tab | ||
add constraint org_site_tab_fk2 foreign key (site_no) | ||
references site_tab(site_no); | ||
|
||
create table org_level | ||
(org_id number(8) not null, | ||
org_level varchar2(1) not null); | ||
|
||
alter table org_level add primary key (org_id); | ||
alter table org_level | ||
add constraint org_level_fk foreign key (org_id)references org_tab(org_id); | ||
alter table org_level | ||
add constraint org_level_ck CHECK (org_level IN ('C','E','M','L')); | ||
|
||
create table sec_hrc_tab | ||
(hrc_code number(4) not null, | ||
hrc_descr varchar2(20) not null); | ||
|
||
create table sec_hrc_org_tab | ||
(hrc_code number(4) not null, | ||
hrc_descr varchar2(20) not null, | ||
org_id NUMBER(8) not null, | ||
org_short_name varchar2(30) not null, | ||
org_long_name varchar2(60)); | ||
|
||
create table sec_hrc_audit | ||
(hrc_code number(4) not null, | ||
num_rows number(8) not null ); | ||
|
||
create sequence hrc_org_seq minvalue 1; | ||
|
||
insert into site_tab values (1,'New York'); | ||
insert into site_tab values (2,'Washington'); | ||
insert into site_tab values (3,'Chicago'); | ||
insert into site_tab values (4,'Dallas'); | ||
insert into site_tab values (5,'San Francisco'); | ||
|
||
insert into hrc_tab values (1,'CEO/COO'); | ||
insert into hrc_tab values (2,'VP'); | ||
insert into hrc_tab values (3,'Director'); | ||
insert into hrc_tab values (4,'Manager'); | ||
insert into hrc_tab values (5,'Analyst'); | ||
|
||
insert into org_tab values | ||
(1,1001,'Office of CEO ABC Inc.','Office of CEO ABC Inc.'); | ||
insert into org_tab values | ||
(1,1002,'Office of CEO XYZ Inc.','Office of CEO XYZ Inc.'); | ||
insert into org_tab values | ||
(1,1003,'Office of CEO DataPro Inc.','Office of CEO DataPro Inc.'); | ||
insert into org_tab values | ||
(2,1004,'Office of VP Sales ABC Inc.','Office of VP Sales ABC Inc.'); | ||
insert into org_tab values | ||
(2,1005,'Office of VP Mktg ABC Inc.','Office of VP Mktg ABC Inc.'); | ||
insert into org_tab values | ||
(2,1006,'Office of VP Tech ABC Inc.','Office of VP Tech ABC Inc.'); | ||
|
||
insert into org_site_tab values (1001,1); | ||
insert into org_site_tab values (1002,2); | ||
insert into org_site_tab values (1003,3); | ||
insert into org_site_tab values (1004,1); | ||
insert into org_site_tab values (1004,2); | ||
insert into org_site_tab values (1004,3); | ||
insert into org_site_tab values (1005,1); | ||
insert into org_site_tab values (1005,4); | ||
insert into org_site_tab values (1005,5); | ||
insert into org_site_tab values (1006,1); | ||
|
||
-- Order Entry Application System | ||
|
||
CREATE TABLE region_tab | ||
(region_id NUMBER(4) PRIMARY KEY, | ||
region_name VARCHAR2(11) NOT NULL); | ||
|
||
CREATE TABLE region_tab_temp AS | ||
SELECT *FROM region_tab; | ||
|
||
CREATE TABLE sec_region_tab | ||
(region_id NUMBER(4) PRIMARY KEY, | ||
region_name VARCHAR2(11) NOT NULL); | ||
|
||
CREATE TABLE supplier_tab | ||
(supp_id NUMBER(6) PRIMARY KEY, | ||
supp_name VARCHAR2(20) NOT NULL | ||
); | ||
|
||
CREATE TABLE order_tab | ||
(order_id NUMBER(10) PRIMARY KEY, | ||
order_date DATE NOT NULL, | ||
total_qty NUMBER, | ||
total_price NUMBER(15,2), | ||
supp_id NUMBER(6) REFERENCES supplier_tab(supp_id)); | ||
|
||
CREATE TABLE order_items | ||
(order_id NUMBER(10) NOT NULL, | ||
item_id VARCHAR2(10) NOT NULL, | ||
unit_price NUMBER(11,2) NOT NULL, | ||
quantity NUMBER); | ||
|
||
ALTER TABLE order_items ADD CONSTRAINT pk_order_items | ||
PRIMARY KEY (order_id,item_id); | ||
|
||
CREATE TABLE error_log | ||
(order_id NUMBER(10) NOT NULL, | ||
error_code NUMBER NOT NULL, | ||
error_text VARCHAR2(1000) NOT NULL, | ||
logged_user VARCHAR2(30) NOT NULL, | ||
logged_date DATE NOT NULL); | ||
|
||
CREATE TABLE order_tran_coming_in | ||
(order_id NUMBER(10) NOT NULL, | ||
order_date DATE NOT NULL, | ||
tran_coming_in_date DATE NOT NULL, | ||
success_flag VARCHAR2(1) DEFAULT 'N' NOT NULL); | ||
|
||
INSERT INTO region_tab VALUES (1,'REGION1'); | ||
INSERT INTO region_tab VALUES (2,'REGION2'); | ||
INSERT INTO region_tab VALUES (3,'REGION3'); | ||
INSERT INTO region_tab VALUES (4,'REGION4'); | ||
|
||
INSERT INTO supplier_tab VALUES (1001,'Supplier 1001'); | ||
|
||
INSERT INTO order_tab VALUES (101,sysdate,100,750,1001); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
Listing 1-1. A Sample PL/SQL Block | ||
|
||
DECLARE | ||
v_item_code VARCHAR2(6); | ||
v_item_descr VARCHAR2(20); | ||
BEGIN | ||
v_item_code :='ITM101'; | ||
v_item_descr :='Spare parts'; | ||
INSERT INTO items_tab VALUES (v_item_code,v_item_descr); | ||
EXCEPTION WHEN OTHERS THEN | ||
dbms_output.put_line(SQLERRM); | ||
END; | ||
/ | ||
|
||
|
||
Listing 1-2. The Modified PL/SQL Code That Uses a Nested Block | ||
|
||
DECLARE | ||
v_item_code VARCHAR2(6); | ||
v_item_descr VARCHAR2(20); | ||
v_num NUMBER(1); | ||
BEGIN | ||
v_item_code :='ITM101'; | ||
v_item_descr :='Spare parts'; | ||
BEGIN | ||
SELECT 1 | ||
INTO v_num | ||
FROM items_tab | ||
WHERE item_code =v_item_code; | ||
EXCEPTION | ||
WHEN NO_DATA_FOUND THEN | ||
v_num :=0; | ||
WHEN OTHERS THEN | ||
dbms_output.put_line('Error in SELECT:'||SQLERRM); | ||
RETURN; | ||
END; | ||
IF (v_num =0)THEN | ||
INSERT INTO items_tab VALUES (v_item_code,v_item_descr); | ||
END IF; | ||
dbms_output.put_line('Successful Completion'); | ||
EXCEPTION WHEN OTHERS THEN | ||
dbms_output.put_line(SQLERRM); | ||
END; | ||
/ | ||
|
||
-- An example of the IF statement | ||
DECLARE | ||
a number :=50; | ||
b number :=-20; | ||
BEGIN | ||
IF (a>b)THEN | ||
dbms_output.put_line('A is greater than B'); | ||
ELSIF (a<b)THEN | ||
dbms_output.put_line('A is < than B'); | ||
ELSE | ||
dbms_output.put_line('A is equal to B'); | ||
END IF; | ||
END; | ||
/ | ||
|
||
-- An example of the simple LOOP | ||
DECLARE | ||
line_length NUMBER :=50; | ||
seperator VARCHAR2(1):='='; | ||
actual_line VARCHAR2(150); | ||
i NUMBER :=1; | ||
BEGIN | ||
LOOP | ||
actual_line :=actual_line ||seperator; | ||
EXIT WHEN i =line_length; | ||
i:=i +1; | ||
END LOOP; | ||
DBMS_OUTPUT.PUT_LINE(actual_line); | ||
END; | ||
/ | ||
|
||
-- A numeric FOR LOOP | ||
DECLARE | ||
line_length NUMBER :=50; | ||
seperator VARCHAR2(1):='='; | ||
actual_line VARCHAR2(150); | ||
BEGIN | ||
FOR idx in 1..line_length LOOP | ||
actual_line :=actual_line ||seperator; | ||
END LOOP; | ||
DBMS_OUTPUT.PUT_LINE(actual_line); | ||
END; | ||
/ | ||
|
||
-- An example using a WHILE LOOP | ||
DECLARE | ||
line_length NUMBER :=50; | ||
seperator VARCHAR2(1):='='; | ||
actual_line VARCHAR2(150); | ||
idx NUMBER :=1; | ||
BEGIN | ||
WHILE (idx<=line_length)LOOP | ||
actual_line :=actual_line ||seperator; | ||
idx :=idx +1 ; | ||
END LOOP; | ||
DBMS_OUTPUT.PUT_LINE(actual_line); | ||
END; | ||
/ | ||
|
||
-- An example of comparison of two numbers | ||
-- using a searched CASE expression | ||
declare | ||
a number :=20; | ||
b number :=-40; | ||
string varchar2(50); | ||
begin | ||
string :=case | ||
when (a>b)then 'A is greater than B' | ||
when (a<b)then 'A is less than B' | ||
else | ||
'A is equal to B' | ||
end; | ||
dbms_output.put_line(string); | ||
end; | ||
/ |
Oops, something went wrong.