Permalink
Browse files

First commit

  • Loading branch information...
Apress
Apress committed Oct 16, 2016
0 parents commit 2af100b8d7fc0ad276bf580509b9cabf5024376e
Showing with 639 additions and 0 deletions.
  1. BIN 978-1-4302-3485-2_Beresniewicz_Ch08_Contract_Oriented_Programming.zip
  2. BIN 978-1-4302-3485-2_Billington_Ch09_PLSQL_SQL.zip
  3. BIN 978-1-4302-3485-2_Bchi_ch11_PLSQLinTheLarge.zip
  4. BIN 978-1-4302-3485-2_Caffrey_Ch10_Choosing_the_Right_Cursor.zip
  5. BIN 978-1-4302-3485-2_Ch15_Nanda_Dependencies_Invalidations.zip
  6. BIN 978-1-4302-3485-2_Crisco_Ch13_Profiling_for_Performance.zip
  7. BIN 978-1-4302-3485-2_Cunningham_Ch07_Know_Your_Code.zip
  8. BIN 978-1-4302-3485-2_Delmolino_Ch03_PLSQL_and_Parallel_Processing.zip
  9. BIN 978-1-4302-3485-2_Harper_ch05_UnitTesting.zip
  10. BIN 978-1-4302-3485-2_Holm_Ch04_PLSQL_Warnings_Conditional_Compilation.zip
  11. BIN 978-1-4302-3485-2_McDonald_Ch06_Bulk_Operations.zip
  12. BIN 978-1-4302-3485-2_Petit_Ch14_Coding_Conventions_and_Error_Handling.zip
  13. BIN 978-1-4302-3485-2_Rosenblum_Ch02_DynamicSQL.zip
  14. +18 −0 978-1-4302-3485-2_Sands_Ch12_Evolutionary/Chap12_Exercises/Exercise_12-1.sql
  15. +26 −0 978-1-4302-3485-2_Sands_Ch12_Evolutionary/Chap12_Exercises/Exercise_12-10.sql
  16. +43 −0 978-1-4302-3485-2_Sands_Ch12_Evolutionary/Chap12_Exercises/Exercise_12-2.sql
  17. +59 −0 978-1-4302-3485-2_Sands_Ch12_Evolutionary/Chap12_Exercises/Exercise_12-3.sql
  18. +29 −0 978-1-4302-3485-2_Sands_Ch12_Evolutionary/Chap12_Exercises/Exercise_12-4.sql
  19. +19 −0 978-1-4302-3485-2_Sands_Ch12_Evolutionary/Chap12_Exercises/Exercise_12-6.sql
  20. +34 −0 978-1-4302-3485-2_Sands_Ch12_Evolutionary/Chap12_Exercises/Exercise_12-7.sql
  21. +66 −0 978-1-4302-3485-2_Sands_Ch12_Evolutionary/Chap12_Exercises/Exercise_12-8.sql
  22. +94 −0 978-1-4302-3485-2_Sands_Ch12_Evolutionary/Chap12_Exercises/Exercise_12-9.sql
  23. BIN 9781430234852.jpg
  24. +27 −0 LICENSE.txt
  25. +15 −0 README.md
  26. +14 −0 contributing.md
  27. +34 −0 scripts/Listing_1_1.sql
  28. +20 −0 scripts/Listing_1_2.sql
  29. +42 −0 scripts/Listing_1_5.sql
  30. +49 −0 scripts/Listing_1_6.sql
  31. +39 −0 scripts/Listing_1_7.sql
  32. +11 −0 scripts/cr_table_top_cust.sql
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -0,0 +1,18 @@
create table emp_phone_numbers (
employee_id number(6) not null,
phone_number varchar2(20) not null,
preferred varchar2(1) default 'N' not null,
phone_type varchar2(10) not null,
constraint emp_phone_numbers_pk
primary key (employee_id, phone_number)) ;
alter table emp_phone_numbers
add constraint emp_phone_numbers_fk1
foreign key (employee_id)
references employees (employee_id) ;
insert into emp_phone_numbers (
select employee_id, phone_number, 'y', 'office'
from employees) ;
commit;
@@ -0,0 +1,26 @@
select * from emp_phone_numbers
where employee_id = 100;
insert into emp_phone_numbers
values (100,'555.312.9876','N','Mobile');
insert into emp_phone_numbers
values (100,'555.321.7345','N','Home');
select * from emp_phone_numbers
where employee_id = 100;
update emp_phone_numbers set preferred = 'N'
where employee_id = 100
and phone_type = 'Office';
update emp_phone_numbers set preferred = 'Y'
where employee_id = 100
and phone_type = 'Mobile';
commit ;
select * from emp_phone_numbers
where employee_id = 100;
@@ -0,0 +1,43 @@
select dept.department_name,
loc.street_address,
loc.city,
loc.state_province,
loc.postal_code,
cty.country_name ,
emp.employee_id ,
emp.last_name,
emp.first_name,
emp.email,
emp.phone_number
from departments dept,
locations loc,
countries cty,
employees emp
where dept.department_id = &DepartmentID
and dept.location_id = loc.location_id
and loc.country_id = cty.country_id
and dept.department_id = emp.department_id
order by dept.department_name, emp.last_name, emp.first_name ;
select dept.department_name,
loc.street_address,
loc.city,
loc.state_province,
loc.postal_code,
cty.country_name ,
emp.employee_id EMP_ID,
emp.last_name,
emp.first_name,
emp.email,
epn.phone_number
from departments dept,
locations loc,
countries cty,
employees emp,
emp_phone_numbers epn
where dept.department_id = &DepartmentID
and dept.location_id = loc.location_id
and loc.country_id = cty.country_id
and dept.department_id = emp.department_id
and emp.employee_id = epn.employee_id
order by dept.department_name, emp.last_name, emp.first_name ;
@@ -0,0 +1,59 @@
CREATE OR REPLACE PROCEDURE GetEmployeeData(
p_dept_id IN NUMBER,
p_emp_cursor OUT SYS_REFCURSOR,
p_status_code OUT NUMBER,
p_status_message OUT VARCHAR2) IS
/********************************************************************************
NAME: GetEmployeeData
PURPOSE: This procedure returns contact information for employees by department
NOTES:
p_status_code status_message
============= ======================================================
0 Success
-20102 Input parameter p_dept_id must not be null.
***************************************************************************************/
BEGIN -- GetEmployeeData
--validate parameters
IF ((p_department_id) IS NULL ) THEN
RAISE_APPLICATION_ERROR(-20102, Input parameter p_dept_id must not be null.',TRUE);
END IF;
OPEN p_emp_cursor FOR
SELECT
dept.department_id,
dept.department_name,
loc.street_address,
loc.city,
loc.state_province,
loc.postal_code,
cty.country_name,
CURSOR (select emp.employee_id,
emp.last_name,
emp.first_name,
emp.email,
emp.phone_number
from employees emp
where emp.department_id = dept.department_id) emp_cursor
FROM
departments dept, locations loc, countries cty
WHERE
dept.department_id = p_dept_id
AND dept.location_id = loc.location_id
AND loc.country_id = cty.country_id
ORDER BY 2,3;
p_status_code:= 0;
p_status_message:= NULL;
EXCEPTION
WHEN OTHERS THEN
p_status_code:= SQLCODE;
p_status_message:= SQLERRM;
END GetEmployeeData;
/
@@ -0,0 +1,29 @@
set serveroutput on
var p_main_cursor REFCURSOR
DECLARE
v_dept_id departments.department_id%TYPE;
v_status_code NUMBER;
v_status_message VARCHAR2(200);
t0 timestamp;
t1 timestamp;
BEGIN
t0:= systimestamp;
v_dept_id := &Department_ID;
GetEmployeeData
(v_dept_id, :p_main_cursor, v_status_code, v_status_message);
t1:= systimestamp;
DBMS_OUTPUT.PUT_LINE('Code=' || v_status_code || 'Message=' || v_status_message);
DBMS_OUTPUT.PUT_LINE('ela=' || (t0 - t1) );
END;
/
print :p_main_cursor
@@ -0,0 +1,19 @@
create table emp_phone_numbers(
employee_id number(6) not null,
phone_number varchar2(20) not null,
preferred varchar2(1) default 'N' not null,
phone_type varchar2(10) not null,
constraint emp_phone_numbers_pk
primary key (employee_id, phone_number)) ;
alter table emp_phone_numbers add constraint emp_phone_numbers_fk1
foreign key (employee_id)
references employees (employee_id) ;
insert into emp_phone_numbers (
select employee_id, phone_number, 'Y', 'Office'
from employees) ;
commit;
alter table employees drop column phone_number;
@@ -0,0 +1,34 @@
select object_type, object_name, status
from user_objects
where status = 'INVALID'
order by object_type, object_name ;
select text
from user_source
where name = 'UPDATE_JOB_HISTORY'
and type = 'TRIGGER'
order by line ;
alter trigger update_job_history compile ;
select text
from user_source
where name = 'SECURE_EMPLOYEES'
and type = 'TRIGGER'
order by line ;
select object_type, object_name, status
from user_objects
where object_name = 'SECURE_DML' ;
select text
from user_source
where name = 'SECURE_DML'
order by line ;
alter trigger secure_employees compile;
select object_type, object_name, status
from user_objects
where status = 'INVALID'
order by object_type, object_name ;
@@ -0,0 +1,66 @@
CREATE OR REPLACE PROCEDURE GetEmployeeData(
p_dept_id IN NUMBER,
p_emp_cursor OUT SYS_REFCURSOR,
p_status_code OUT NUMBER,
p_status_message OUT VARCHAR2) IS
/**************************************************************************************
NAME: GetEmployeeData
PURPOSE: This procedure returns contact information for employees by department
NOTES:
p_status_code status_message
============= ===========================================================
0 Success
-20102 'Input parameter p_dept_id must not be null.'
***************************************************************************************/
BEGIN -- GetEmployeeData
--validate parameters
IF ((p_dept_id) IS NULL ) THEN
RAISE_APPLICATION_ERROR(-20102, 'Input parameter p_dept_id must not be null.', TRUE);
END IF;
OPEN p_emp_cursor FOR
SELECT
dept.department_id, dept.department_name,
loc.street_address,
loc.city, loc.state_province, loc.postal_code,
cty.country_name,
CURSOR (select emp.employee_id,
emp.last_name,
emp.first_name,
emp.email,
eph.phone_number
from employees emp , emp_phone_numbers eph
where emp.department_id = dept.department_id
and emp.employee_id = eph.employee_id
and eph.preferred = 'Y'
order by emp.employee_id) emp_cursor
FROM
departments dept, locations loc, countries cty
WHERE dept.department_id = p_dept_id
AND dept.location_id = loc.location_id
AND loc.country_id = cty.country_id ;
p_status_code:= 0;
p_status_message:= NULL;
EXCEPTION
WHEN OTHERS THEN
p_status_code:= SQLCODE;
p_status_message:= SQLERRM;
END GetEmployeeData;
/
select object_type, object_name, status
from user_objects
where status = 'INVALID'
order by object_type, object_name ;
@@ -0,0 +1,94 @@
CREATE OR REPLACE PROCEDURE GetEmployeeData_MultiPhoneNo(
p_dept_id IN NUMBER,
p_emp_cursor OUT SYS_REFCURSOR,
p_status_code OUT NUMBER,
p_status_message OUT VARCHAR2) IS
/***************************************************************************************
NAME: GetEmployeeData_MultiPhoneNo
PURPOSE: This procedure returns contact information for employees by department
NOTES:
p_status_code status_message
============= ===========================================================
0 Success
-20102 Input parameter p_dept_id must not be null.
***************************************************************************************/
BEGIN -- GetEmployeeData_MultiPhoneNo
--validate parameters
IF ((p_dept_id) IS NULL ) THEN
RAISE_APPLICATION_ERROR(-20102, 'Input parameter p_dept_id must not be null.', TRUE);
END IF;
OPEN p_emp_cursor FOR
SELECT
dept.department_id,
dept.department_name,
loc.street_address,
loc.city,
loc.state_province,
loc.postal_code,
cty.country_name,
CURSOR (select emp.employee_id,
emp.last_name,
emp.first_name,
emp.email,
eph.preferred,
eph.phone_type,
eph.phone_number
from employees emp , emp_phone_numbers eph
where emp.department_id = dept.department_id
and emp.employee_id = eph.employee_id
order by emp.employee_id) emp_cursor
FROM
departments dept, locations loc, countries cty
WHERE dept.department_id = p_dept_id
AND dept.location_id = loc.location_id
AND loc.country_id = cty.country_id ;
p_status_code:= 0;
p_status_message:= NULL;
EXCEPTION
WHEN OTHERS THEN
p_status_code:= SQLCODE;
p_status_message:= SQLERRM;
END GetEmployeeData_MultiPhoneNo;
/
---- Create new test script to execute this procedure
---- only the procedure name is changed
set serveroutput on
var p_main_cursor REFCURSOR
DECLARE
v_dept_id departments.department_id%TYPE;
v_status_code NUMBER;
v_status_message VARCHAR2(200);
t0 timestamp;
t1 timestamp;
BEGIN
t0:= systimestamp;
v_dept_id := &Department_ID;
GetEmployeeData_MultiPhoneNo
(v_dept_id, :p_main_cursor, v_status_code, v_status_message);
t1:= systimestamp;
DBMS_OUTPUT.PUT_LINE('code=' || v_status_code || 'message=' || v_status_message);
DBMS_OUTPUT.PUT_LINE('ela=' || (t0 - t1) );
END;
/
print :p_main_cursor
BIN +11.2 KB 9781430234852.jpg
Binary file not shown.
Oops, something went wrong.

0 comments on commit 2af100b

Please sign in to comment.