Professional Documents
Culture Documents
Analyzing PL/SQL Code
Analyzing PL/SQL Code
Create a package with various queries that you can easily call:
EXECUTE query_code_pkg.encap_compliance
1
Programs that reference tables or views
OE.CREDIT_CARD_PKG,OE.CUSTOMERS
OE.LOAD_PRODUCT_IMAGE,OE.PRODUCT_INFORMATION
OE.SET_VIDEO,OE.CUSTOMERS
OE.WRITE_LOB,OE.PRODUCT_DESCRIPTIONS
...
EXECUTE query_code_pkg.find_text_in_code('customers')
2
Checking for presence of customers:
CREDIT_CARD_PKG-12, FROM customers
CREDIT_CARD_PKG-36, UPDATE customers
CREDIT_CARD_PKG-41, UPDATE customers
SET_VIDEO-6, SELECT cust_first_name FROM customers
SET_VIDEO-13, UPDATE customers SET video = file_ptr
...
Use Reports:
1
Results 5
object_name
null
null
describe_procedure
EXEC use_dbms_describe.get_data('ORDERS_APP_PKG.THE_PREDICATE')
2
Name Mode Position Datatype
This is the RETURN data for the function: 1 0 1
P_SCHEMA 0 1 1
P_NAME 0 2 1
10 rows selected.
Use Reports:
1
2 3
Results:
DBMS_UTILITY.FORMAT_ERROR_BACKTRACE:
• Shows you the call stack at the point where an exception is
raised
• Returns:
– The backtrace string
– A null string if no errors are being handled
Backtrace string
Null string
Raised format_error_backtrace
exception
Results:
EXECUTE top_with_logging
Error_Stack...
ORA-01476: divisor is equal to zero
Error_Backtrace...
ORA-06512: at "OE.P0", line 5
ORA-06512: at "OE.P1", line 3
ORA-06512: at "OE.P2", line 3
ORA-06512: at "OE.P3", line 3
ORA-06512: at "OE.P4", line 2
ORA-06512: at "OE.P5", line 2
ORA-06512: at "OE.TOP_WITH_LOGGING", line 7
----------
• Definition:
– Is a tool that is used for extracting, organizing, and storing
user-supplied identifiers from PL/SQL source code
– Works with the PL/SQL compiler
– Gathers data on scoping and overloading
• Benefits
– Can potentially increase developer productivity
– Is a valuable resource in helping developers understand
source code
– Can be used to build a PL/SQL IDE
Column Description
OWNER Owner of the identifier
Results:
IDENTIFIER_USAGE_CONTEXTS
-------------------------------------------------------------
Credit_Card_Pkg..... package definition
Cust_Card_Info.... function definition
P_Cust_Id....... formal in declaration
P_Card_Info..... formal in out declaration
V_Card_Info_Exis variable declaration
P_Card_Info..... formal in out assignment
P_Cust_Id....... formal in reference
Plitblm......... synonym call
P_Card_Info... formal in out reference
V_Card_Info_Ex variable assignment
V_Card_Info_Exis variable assignment
...
57 rows selected.
Name Description
FETCH_XML This function returns the XML metadata for an object
as an XMLType.
FETCH_DDL This function returns the DDL (either to create or to
drop the object) into a predefined nested table.
FETCH_CLOB This function returns the objects (transformed or not)
as a CLOB.
FETCH_XML_CLOB This procedure returns the XML metadata for the
objects as a CLOB in an IN OUT NOCOPY parameter
to avoid expensive LOB copies.
• Syntax:
PROCEDURE set_filter
( handle IN NUMBER,
name IN VARCHAR2,
value IN VARCHAR2|BOOLEAN|NUMBER,
object_type_path VARCHAR2
);
• Example:
...
DBMS_METADATA.SET_FILTER (handle, 'NAME', 'OE');
...
There are over 70 filters that are organized into object type
categories such as:
• Named objects
• Tables
• Objects dependent on tables
• Index
• Dependent objects
• Granted objects
• Table data
• Index statistics
• Constraints
• All object types
• Database export
DBMS_METADATA.SET_FILTER(handle, 'SCHEMA_EXPR',
'IN (''PAYROLL'', ''OE'')');
DBMS_METADATA.SET_FILTER(handle, 'EXCLUDE_PATH_EXPR',
'=''FUNCTION''');
DBMS_METADATA.SET_FILTER(handle, 'EXCLUDE_PATH_EXPR',
'=''PROCEDURE''');
DBMS_METADATA.SET_FILTER(handle, 'EXCLUDE_PATH_EXPR',
'=''PACKAGE''');
DBMS_METADATA.SET_FILTER(handle, 'EXCLUDE_NAME_EXPR',
'LIKE ''PAYROLL%''', 'VIEW');
Name Description
GET_XXX The GET_XML and GET_DDL functions return
metadata for a single named object.
GET_DEPENDENT_XXX This function returns metadata for a dependent
object.
GET_GRANTED_XXX This function returns metadata for a granted
object.
BEGIN
DBMS_METADATA.SET_TRANSFORM_PARAM(
DBMS_METADATA.SESSION_TRANSFORM, 1
'STORAGE', false);
END;
/
SELECT DBMS_METADATA.GET_DDL('TABLE',u.table_name)
FROM user_all_tables u 2
WHERE u.nested = 'NO'
AND (u.iot_type IS NULL OR u.iot_type = 'IOT');
BEGIN
DBMS_METADATA.SET_TRANSFORM_PARAM( 3
DBMS_METADATA.SESSION_TRANSFORM, 'DEFAULT');
END;
/