Entity Relationship Model for PL/Scope

Today I found a sketch of an ERD from last year when I looked at the new features of PL/Scope in version 12.2. It looked a bit complicated and also wrong. So, I decided to refactor it using SQL Developer Data Modeler and share the result.

You find the model in the plscope-utils Github project here.

The implementation provides the following views:

  • DBA/ALL/USER_IDENTIFIERSfor the entities “Identifier Declaration” and “DB Object Usage”
  • DBA/ALL/USER_STATEMENTSfor the entities “Identifier Declaration”, “SQL Stmt Usage” and  “SQL Statement”

For me the most interesting entity was the “Identifier Declaration”, because it helped me to understand the signature attribute/column. PL/Scope creates a signature for every database object and all its components when a database object is compiled with PL/Scope or when a referenced object cannot be compiled with PL/Scope. I call those objects “Secondary Objects”. Such objects are tables, views, materialized views, operators or sequences. Hence you find PL/Scope metadata for every table which is referenced in the PL/SQL code after compiling it with PL/Scope. Here’s an example:

PL/Scope Metadata of Table EMP
SELECT usage, type, name, line, col, usage_id, usage_context_id 
  FROM user_identifiers
 WHERE object_type = 'TABLE'
   AND object_name = 'EMP'
 ORDER BY line, col;

USAGE       TYPE   NAME     LINE  COL USAGE_ID USAGE_CONTEXT_ID
----------- ------ -------- ---- ---- -------- ----------------
DECLARATION TABLE  EMP         1   15        1                0
DECLARATION COLUMN EMPNO       1   22        2                1
DECLARATION COLUMN ENAME       1   51        3                1
DECLARATION COLUMN JOB         1   77        4                1
DECLARATION COLUMN MGR         1  100        5                1
DECLARATION COLUMN HIREDATE    1  118        6                1
DECLARATION COLUMN SAL         1  134        7                1
DECLARATION COLUMN COMM        1  152        8                1
DECLARATION COLUMN DEPTNO      1  171        9                1

The PL/Scope metadata for the table emp will be removed automatically when they are not used by “Primary Objects” (objects which can be compiled with PL/Scope) anymore. Quite nice.

1 Comment

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.