Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 1e143b8

Browse files
authored
Merge pull request #75 from stevenfeuerstein/master
many files and new folders
2 parents 3c9f270 + 7942dba commit 1e143b8

Some content is hidden

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

43 files changed

+6723
-3
lines changed

‎plsql/code-analysis/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
As a database programming language, PL/SQL code is stored in the Oracle Database.
2-
That means that we can analyze our code using data dictionary views, most importantly
3-
ALL_IDENTIFIERS and ALL_STATEMENTS, which are populated by PL/Scope.
1+
As a database programming language, PL/SQL code is stored in the Oracle Database. That means that we can analyze our code using data dictionary views, most importantly the ALL_IDENTIFIERS and ALL_STATEMENTS views, which are populated by PL/Scope.
42

53
This folder offers a set of stand-alone queries and procedures that demonstrate PL/Scope and give you a quick and easy way to get started with this fantastic utility.
64

75
Philipp Salvisberg has also put together a very nice utility full of packages and views that can take you a long way towards fully leverage PL/Scope. Check it out here: https://github.com/PhilippSalvisberg/plscope-utils
6+
7+
For a broader roundup of resources related to PL/Scope, check out Steven Feuerstein's blog post here: https://stevenfeuersteinonplsql.blogspot.com/2018/07/the-plscope-resource-center.html
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
/*
2+
When contemplating a change to a subprogram, impact analysis is critical.
3+
And the first thing you need to know is: where is the subprogram called?
4+
With PL/Scope (11.1), you can now get the definitive answer to that question,
5+
regardless of possible re-uses of the same name in different program units,
6+
by utilizing the unique signature values stored in ALL/USER_IDENTIFIERS.
7+
*/
8+
9+
-- Turn on PL/Scope
10+
ALTER SESSION SET plscope_settings='identifiers:all' ;
11+
12+
-- Who Calls Me? Answered by PL/Scope
13+
-- I look up the declaration of that subprogram in the package, then search
14+
-- for its signature across all other program units compiled with PL/Scope enabled.
15+
CREATE OR REPLACE PROCEDURE who_calls_me (pkg_in IN VARCHAR2,
16+
prog_in IN VARCHAR2)
17+
IS
18+
BEGIN
19+
FOR rec
20+
IN (SELECT srch.object_name, srch.name
21+
FROM user_identifiers srch, user_identifiers src
22+
WHERE src.object_name = pkg_in
23+
AND src.object_type = 'PACKAGE'
24+
AND src.usage = 'DECLARATION'
25+
AND src.name = prog_in
26+
AND src.signature = srch.signature
27+
AND srch.usage = 'CALL')
28+
LOOP
29+
DBMS_OUTPUT.put_line (
30+
rec.object_name || ' calls ' || pkg_in || '.' || prog_in);
31+
END LOOP;
32+
END;
33+
/
34+
35+
-- Create Some Program Units
36+
CREATE OR REPLACE PACKAGE my_pkg1
37+
IS
38+
PROCEDURE my_proc;
39+
END;
40+
/
41+
42+
CREATE OR REPLACE PACKAGE BODY my_pkg1
43+
IS
44+
PROCEDURE my_proc
45+
IS
46+
BEGIN
47+
NULL;
48+
END;
49+
END;
50+
/
51+
52+
CREATE OR REPLACE PACKAGE my_pkg2
53+
IS
54+
PROCEDURE my_proc;
55+
END;
56+
/
57+
58+
CREATE OR REPLACE PACKAGE BODY my_pkg2
59+
IS
60+
PROCEDURE my_proc
61+
IS
62+
BEGIN
63+
NULL;
64+
END;
65+
END;
66+
/
67+
68+
CREATE OR REPLACE PROCEDURE my_proc1
69+
IS
70+
BEGIN
71+
my_pkg1.my_proc;
72+
END;
73+
/
74+
75+
CREATE OR REPLACE PROCEDURE my_proc2
76+
IS
77+
BEGIN
78+
my_pkg2.my_proc;
79+
END;
80+
/
81+
82+
-- Check for Usages
83+
BEGIN
84+
who_calls_me ('MY_PKG1', 'MY_PROC');
85+
END;
86+
/
87+
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
As of 12.2, PL/Scope now analyzes the static SQL statements that
3+
appear in your PL/SQL program units. It allows you to answer with ease
4+
questions like "Where do I use hints in my SQL statements?"
5+
6+
Doc: http://docs.oracle.com/database/122/ADFNS/plscope.htm#ADFNS022
7+
*/
8+
9+
ALTER SESSION SET plscope_settings='identifiers:all, statements:all';
10+
11+
CREATE OR REPLACE PROCEDURE proc1
12+
IS
13+
l_id INTEGER;
14+
BEGIN
15+
SELECT /*+ result_cache */
16+
employee_id
17+
INTO l_id
18+
FROM hr.employees
19+
WHERE last_name = 'KING';
20+
END;
21+
/
22+
23+
CREATE OR REPLACE PROCEDURE proc2
24+
IS
25+
TYPE nt IS TABLE OF INTEGER;
26+
27+
l_ids nt;
28+
BEGIN
29+
SELECT /*+ FIRST_ROWS(10) */
30+
employee_id
31+
BULK COLLECT INTO l_ids
32+
FROM hr.employees;
33+
END;
34+
/
35+
36+
CREATE OR REPLACE PROCEDURE proc3
37+
IS
38+
TYPE nt IS TABLE OF INTEGER;
39+
40+
l_ids nt;
41+
BEGIN
42+
SELECT employee_id
43+
BULK COLLECT INTO l_ids
44+
FROM hr.employees;
45+
END;
46+
/
47+
48+
-- Does the statement have a hint?
49+
-- What could be simpler?
50+
SELECT object_name,
51+
line,
52+
full_text
53+
FROM user_statements
54+
WHERE has_hint = 'YES';
55+

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /