Skip to content

Commit 5885ce7

Browse files
author
O'Reilly Media, Inc
committed
Initial commit
0 parents  commit 5885ce7

File tree

574 files changed

+82317
-0
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

574 files changed

+82317
-0
lines changed

Chapters_27and28_OPLSQL5e.pdf

651 KB
Binary file not shown.

OPP5.WEB.CODE/#README.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
Oracle PL/SQL Programming 5th Edition
2+
3+
Code Companion
4+
5+
6+
The OPP5code.zip contains a wide variety of code used in this book. You are welcome to peruse the zip file directly, but you are better off using references to files in this zip as an "index" to its contents. To find a particular example on the book's web site, look for the filename cited in the text. For many examples, you will find filenames in the following form provided as a comment at the beginning of the example shown in the book, as shown here:
7+
8+
/* File on web: fullname.pkg */
9+
10+
If the code snippet in which you are interested does not have a "File on web" comment, then you should check the corresponding chapter code file . A chapter code file contains all the code fragments and examples that do not merit their own file, but that may prove useful to you for copy-and-paste operations. These files also contain the DDL statements to create tables and other objects on which the code may depend. The chapter code file is named chNN_code.sql, where NN is the number of the chapter.
11+
12+
The hr_schema_install.sql script will create the standard Oracle human resources demonstration tables, such as employees and departments. These tables are used in examples throughout the book.
13+
14+
Finally, unless otherwise noted in a file, you have the permission of the authors to use this code in your own application development efforts. Remember, however, that we do not guarantee any of this code to be bug-free. You are responsible for testing anything you choose to use!

OPP5.WEB.CODE/10g_authors.pkg

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
CREATE OR REPLACE PACKAGE authors_pkg
2+
IS
3+
steven_authors strings_nt
4+
:= strings_nt ('ROBIN HOBB'
5+
, 'ROBERT HARRIS'
6+
, 'DAVID BRIN'
7+
, 'SHERI S. TEPPER'
8+
, 'CHRISTOPHER ALEXANDER'
9+
);
10+
veva_authors strings_nt
11+
:= strings_nt ('ROBIN HOBB'
12+
, 'SHERI S. TEPPER'
13+
, 'ANNE MCCAFFREY'
14+
);
15+
16+
eli_authors strings_nt
17+
:= strings_nt ( 'SHERI S. TEPPER'
18+
, 'DAVID BRIN'
19+
);
20+
21+
PROCEDURE show_authors (
22+
title_in IN VARCHAR2
23+
, authors_in IN strings_nt
24+
);
25+
END;
26+
/
27+
SHO ERR
28+
29+
CREATE OR REPLACE PACKAGE BODY authors_pkg
30+
IS
31+
PROCEDURE show_authors (
32+
title_in IN VARCHAR2
33+
, authors_in IN strings_nt
34+
)
35+
IS
36+
BEGIN
37+
DBMS_OUTPUT.put_line (title_in);
38+
39+
FOR indx IN authors_in.FIRST .. authors_in.LAST
40+
LOOP
41+
DBMS_OUTPUT.put_line (indx || ' = ' || authors_in (indx));
42+
END LOOP;
43+
44+
DBMS_OUTPUT.put_line ('_');
45+
END show_authors;
46+
END;
47+
/
48+
SHO ERR
49+
50+
51+
52+
/*======================================================================
53+
| Supplement to the fifth edition of Oracle PL/SQL Programming by Steven
54+
| Feuerstein with Bill Pribyl, Copyright (c) 1997-2009 O'Reilly Media, Inc.
55+
| To submit corrections or find more code samples visit
56+
| http://oreilly.com/catalog/9780596514464/
57+
*/

OPP5.WEB.CODE/10g_coll_unordered.sql

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
DECLARE
2+
TYPE nested_tab_t IS TABLE OF INTEGER;
3+
4+
tab_1 nested_tab_t := nested_tab_t (1, 2, 3, 4, 5, 6, 7);
5+
tab_2 nested_tab_t := nested_tab_t (7, 6, 5, 4, 3, 2, 1);
6+
7+
PROCEDURE tabs_equal (i_tab_1 IN nested_tab_t, i_tab_2 IN nested_tab_t)
8+
IS
9+
v_equal BOOLEAN := i_tab_1 = i_tab_2;
10+
BEGIN
11+
IF v_equal IS NULL
12+
THEN
13+
DBMS_OUTPUT.put_line ('null');
14+
ELSIF v_equal
15+
THEN
16+
DBMS_OUTPUT.put_line ('equal');
17+
ELSE
18+
DBMS_OUTPUT.put_line ('not equal');
19+
END IF;
20+
END tabs_equal;
21+
BEGIN
22+
tabs_equal (tab_1, tab_2);
23+
tab_1.EXTEND (1);
24+
tabs_equal (tab_1, tab_2);
25+
tab_2.EXTEND (1);
26+
tabs_equal (tab_1, tab_2);
27+
END;
28+
29+
30+
31+
/*======================================================================
32+
| Supplement to the fifth edition of Oracle PL/SQL Programming by Steven
33+
| Feuerstein with Bill Pribyl, Copyright (c) 1997-2009 O'Reilly Media, Inc.
34+
| To submit corrections or find more code samples visit
35+
| http://oreilly.com/catalog/9780596514464/
36+
*/

OPP5.WEB.CODE/10g_compare.sql

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
DECLARE
2+
TYPE clientele IS TABLE OF VARCHAR2 (64);
3+
4+
group1 clientele := clientele ('Customer 1', 'Customer 2');
5+
group2 clientele := clientele ('Customer 1', 'Customer 3', NULL);
6+
group3 clientele := clientele ('Customer 3', NULL, 'Customer 1');
7+
BEGIN
8+
IF group1 = group2
9+
THEN
10+
DBMS_OUTPUT.put_line ('Group 1 = Group 2');
11+
ELSIF group1 != group2
12+
THEN
13+
DBMS_OUTPUT.put_line ('Group 1 != Group 2');
14+
END IF;
15+
16+
IF group2 != group3
17+
THEN
18+
DBMS_OUTPUT.put_line ('Group 2 != Group 3');
19+
ELSIF group2 = group3
20+
THEN
21+
DBMS_OUTPUT.put_line ('Group 2 = Group 3');
22+
END IF;
23+
END;
24+
/
25+
26+
27+
28+
/*======================================================================
29+
| Supplement to the fifth edition of Oracle PL/SQL Programming by Steven
30+
| Feuerstein with Bill Pribyl, Copyright (c) 1997-2009 O'Reilly Media, Inc.
31+
| To submit corrections or find more code samples visit
32+
| http://oreilly.com/catalog/9780596514464/
33+
*/

OPP5.WEB.CODE/10g_compare_old.sql

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
CREATE OR REPLACE PACKAGE emp_coll_pkg
2+
IS
3+
TYPE employee_tt IS TABLE OF employee%ROWTYPE;
4+
5+
FUNCTION equal (coll1_in IN employee_tt, coll2_in IN employee_tt)
6+
RETURN BOOLEAN;
7+
END emp_coll_pkg;
8+
/
9+
10+
CREATE OR REPLACE PACKAGE BODY emp_coll_pkg
11+
IS
12+
FUNCTION equal (coll1_in IN employee_tt, coll2_in IN employee_tt)
13+
RETURN BOOLEAN
14+
IS
15+
l_count1 PLS_INTEGER := coll1_in.COUNT;
16+
l_count2 PLS_INTEGER := coll2_in.COUNT;
17+
l_row PLS_INTEGER := coll1_in.FIRST;
18+
retval BOOLEAN;
19+
20+
FUNCTION row_equal (
21+
row1_in IN employee%ROWTYPE
22+
, row2_in IN employee%ROWTYPE
23+
)
24+
RETURN BOOLEAN
25+
IS
26+
retval BOOLEAN;
27+
BEGIN
28+
retval :=
29+
row1_in.employee_id = row2_in.employee_id
30+
AND row1_in.last_name = row2_in.last_name
31+
AND row1_in.first_name = row2_in.first_name
32+
AND row1_in.middle_initial = row2_in.middle_initial
33+
AND row1_in.job_id = row2_in.job_id
34+
AND row1_in.manager_id = row2_in.manager_id
35+
AND row1_in.hire_date = row2_in.hire_date
36+
AND row1_in.salary = row2_in.salary
37+
AND row1_in.commission = row2_in.commission
38+
AND row1_in.department_id = row2_in.department_id
39+
AND row1_in.empno = row2_in.empno
40+
AND row1_in.ename = row2_in.ename
41+
AND row1_in.created_by = row2_in.created_by
42+
AND row1_in.created_on = row2_in.created_on
43+
AND row1_in.changed_by = row2_in.changed_by
44+
AND row1_in.changed_on = row2_in.changed_on;
45+
RETURN retval;
46+
END row_equal;
47+
BEGIN
48+
retval := l_count1 = l_count2;
49+
50+
IF retval
51+
THEN
52+
LOOP
53+
EXIT WHEN l_row IS NULL OR NOT retval;
54+
retval := row_equal (coll1_in (l_row), coll2_in (l_row));
55+
l_row := coll1_in.NEXT (l_row);
56+
END LOOP;
57+
END IF;
58+
59+
RETURN retval;
60+
END;
61+
END emp_coll_pkg;
62+
/
63+
64+
65+
66+
/*======================================================================
67+
| Supplement to the fifth edition of Oracle PL/SQL Programming by Steven
68+
| Feuerstein with Bill Pribyl, Copyright (c) 1997-2009 O'Reilly Media, Inc.
69+
| To submit corrections or find more code samples visit
70+
| http://oreilly.com/catalog/9780596514464/
71+
*/
72+

OPP5.WEB.CODE/10g_compwarn.sql

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
alter session set plsql_warnings='ENABLE:ALL'
2+
3+
4+
5+
/*======================================================================
6+
| Supplement to the fifth edition of Oracle PL/SQL Programming by Steven
7+
| Feuerstein with Bill Pribyl, Copyright (c) 1997-2009 O'Reilly Media, Inc.
8+
| To submit corrections or find more code samples visit
9+
| http://oreilly.com/catalog/9780596514464/
10+
*/

OPP5.WEB.CODE/10g_fav_union1.sql

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
DECLARE
2+
our_favorites
3+
strings_nt := strings_nt ();
4+
BEGIN
5+
our_favorites :=
6+
authors_pkg.steven_authors
7+
MULTISET UNION
8+
authors_pkg.veva_authors;
9+
10+
authors_pkg.show_authors (
11+
'STEVEN then VEVA', our_favorites);
12+
END;
13+
/
14+
15+
16+
17+
/*======================================================================
18+
| Supplement to the fifth edition of Oracle PL/SQL Programming by Steven
19+
| Feuerstein with Bill Pribyl, Copyright (c) 1997-2009 O'Reilly Media, Inc.
20+
| To submit corrections or find more code samples visit
21+
| http://oreilly.com/catalog/9780596514464/
22+
*/

OPP5.WEB.CODE/10g_fav_union2.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
DECLARE
2+
our_favorites
3+
strings_nt := strings_nt ();
4+
BEGIN
5+
our_favorites :=
6+
authors_pkg.veva_authors
7+
MULTISET UNION
8+
authors_pkg.steven_authors;
9+
10+
authors_pkg.show_authors (
11+
'VEVA THEN STEVEN', our_favorites);
12+
END;
13+
/
14+
15+
16+
17+
/*======================================================================
18+
| Supplement to the fifth edition of Oracle PL/SQL Programming by Steven
19+
| Feuerstein with Bill Pribyl, Copyright (c) 1997-2009 O'Reilly Media, Inc.
20+
| To submit corrections or find more code samples visit
21+
| http://oreilly.com/catalog/9780596514464/
22+
*/
23+

OPP5.WEB.CODE/10g_fav_union3.sql

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
DECLARE
2+
our_favorites
3+
strings_nt := strings_nt ();
4+
BEGIN
5+
our_favorites :=
6+
authors_pkg.veva_authors
7+
MULTISET UNION DISTINCT
8+
authors_pkg.steven_authors;
9+
10+
authors_pkg.show_authors (
11+
'VEVA THEN STEVEN DISTINCT', our_favorites);
12+
END;
13+
/
14+
15+
16+
17+
/*======================================================================
18+
| Supplement to the fifth edition of Oracle PL/SQL Programming by Steven
19+
| Feuerstein with Bill Pribyl, Copyright (c) 1997-2009 O'Reilly Media, Inc.
20+
| To submit corrections or find more code samples visit
21+
| http://oreilly.com/catalog/9780596514464/
22+
*/
23+

OPP5.WEB.CODE/10g_favorites.pkg

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
CREATE OR REPLACE PACKAGE authors_pkg
2+
IS
3+
steven_authors strings_nt
4+
:= strings_nt ('ROBIN HOBB'
5+
, 'ROBERT HARRIS'
6+
, 'DAVID BRIN'
7+
, 'SHERI S. TEPPER'
8+
, 'CHRISTOPHER ALEXANDER'
9+
);
10+
veva_authors strings_nt
11+
:= strings_nt ('ROBIN HOBB'
12+
, 'SHERI S. TEPPER'
13+
, 'ANNE MCCAFFREY'
14+
);
15+
16+
eli_authors strings_nt
17+
:= strings_nt ('PIERS ANTHONY'
18+
, 'SHERI S. TEPPER'
19+
, 'DAVID BRIN'
20+
);
21+
22+
PROCEDURE show_authors (
23+
title_in IN VARCHAR2
24+
, authors_in IN strings_nt
25+
);
26+
END;
27+
/
28+
29+
CREATE OR REPLACE PACKAGE BODY authors_pkg
30+
IS
31+
PROCEDURE show_authors (
32+
title_in IN VARCHAR2
33+
, authors_in IN strings_nt
34+
)
35+
IS
36+
BEGIN
37+
DBMS_OUTPUT.put_line (title_in);
38+
39+
FOR indx IN authors_in.FIRST .. authors_in.LAST
40+
LOOP
41+
DBMS_OUTPUT.put_line (indx || ' = ' || authors_in (indx));
42+
END LOOP;
43+
44+
DBMS_OUTPUT.put_line ('_');
45+
END show_authors;
46+
END;
47+
/
48+
49+
50+
51+
/*======================================================================
52+
| Supplement to the fifth edition of Oracle PL/SQL Programming by Steven
53+
| Feuerstein with Bill Pribyl, Copyright (c) 1997-2009 O'Reilly Media, Inc.
54+
| To submit corrections or find more code samples visit
55+
| http://oreilly.com/catalog/9780596514464/
56+
*/

0 commit comments

Comments
 (0)