1 package dbms_preprocessor authid current_user as
2
3 ------------
4 -- OVERVIEW
5 --
6 -- This package provides subprograms to print or retrieve the source
7 -- text of a PL/SQL unit in its post-processed form.
8 --
9 -- There are three styles of subprograms.
10 -- (1) subprograms that take a schema name, a unit type name, and the
11 -- unit name.
12 -- (2) subprograms that take a VARCHAR2 string which contains the
13 -- source text of an arbitrary PL/SQL compilation unit.
14 -- (3) subprograms that take a VARCHAR2 index-by table which
15 -- contains the segmented source text of an arbitrary PL/SQL
16 -- PL/SQL compilation unit.
17 --
18 -- Subprograms of the first style are used to print or retrieve the
19 -- post-processed source text of a stored PL/SQL unit. The user must
20 -- have the privileges necessary to view the original source text of
21 -- this unit. The user must also specify the schema in which the unit
22 -- is defined, the type of the unit, and the name of the unit. If the
23 -- schema is null, then the current user schema is used. If the status
24 -- of the stored unit is VALID and the user has the required privilege,
25 -- then the post-processed source text is guaranteed to be the same as
26 -- that of the unit when it was last time compiled.
27 --
28 -- Subprograms of the second or third style are used to generate
29 -- post-processed source text in the current user schema. The source
30 -- text is passed in as a single VARCHAR2 string in the second style
31 -- or as a VARCHAR2 index-by table in the third style. The source text
32 -- can represent an arbitrary PL/SQL compilation unit. A typical usage
33 -- is to pass the source text of an anonymous block and generate its
34 -- post-processed source text in the current user schema. The third
35 -- style can be useful when the source text exceeds the VARCHAR2 length
36 -- limit.
37 --
38 -- NOTES:
39 -- 1. For subprograms of the first style, the status of the stored
40 -- PL/SQL unit does not need to be VALID. Likewise, the source text
41 -- passed in as a VARCHAR2 string or a VARCHAR2 index-by table may
42 -- contain compile time errors. If errors are found when generating
43 -- the post-processed source, the error message text will also appear
44 -- at the end of the post-processed source text. In some cases,
45 -- the preprocessing can be aborted because of errors. When this
46 -- happens, the post-processed source text will appear to be
47 -- incomplete and the associated error message can help to indicate
48 -- that an error has occurred during preprocessing.
49 -- 2. For subprograms of the second or third style, the source text can
50 -- represent any arbitrary PL/SQL compilation unit. However, the
51 -- source text of a valid PL/SQL compilation unit cannot include
52 -- commonly used prefixes such as "create or replace". In general,
53 -- the input source should be syntactically prepared in a way as if
54 -- it were obtained from the all_source view. The following list
55 -- gives some examples of valid initial syntax for some PL/SQL
56 -- compilation units.
57 -- anonymous block (begin | declare) ...
58 -- package package <name> ...
59 -- package body package body <name> ...
60 -- procedure procedure <name> ...
61 -- function function <name> ...
62 -- type type <name> ...
63 -- type body type body <name> ...
64 -- trigger (begin | declare) ...
65 -- If the source text represents a named PL/SQL unit that is valid,
66 -- that unit will not be created after its post-processed source text
67 -- is generated.
68 -------------
69 -- TYPES
70 --
71 -- Define type to store lines of post-processed source text
72
73 type source_lines_t is
74 table of varchar2(32767) index by binary_integer;
75
76 wrapped_input exception;
77 pragma exception_init(wrapped_input, -24241);
78
79 empty_input exception;
80 pragma exception_init(empty_input, -24236);
81
82 ---------------------------
83 -- PROCEDURES AND FUNCTIONS
84
85 -- Name:
86 -- print_post_processed_source
87 -- Description:
88 -- Given a stored PL/SQL unit, print its post-processed source text.
89 -- Input arguments:
90 -- object_type
91 -- Must be one of "PACKAGE", "PACKAGE BODY", "PROCEDURE", "FUNCTION",
92 -- "TYPE", "TYPE BODY", or "TRIGGER".
93 -- schema_name
94 -- The schema name. If NULL then use current schema.
95 -- object_name
96 -- The name of the object.
97 -- The object_type is always case insensitive. The schema_name or
98 -- object_name is case insensitive unless a quoted identifier is used.
99 -- Exceptions:
100 -- ORA-24234: insufficient privileges or object does not exist.
101 -- ORA-24235: bad value for object type. Should be one of PACKAGE,
102 -- PACKAGE BODY, PROCEDURE, FUNCTION, TYPE, TYPE BODY, or TRIGGER.
103 -- ORA-00931: missing identifier. The object_name should not be null.
104 -- ORA-06502: PL/SQL: numeric or value error: character string buffer
105 -- too small. A line is too long ( > 32767 bytes).
106 procedure print_post_processed_source(object_type varchar2,
107 schema_name varchar2,
108 object_name varchar2);
109
110 -- Name:
111 -- print_post_processed_source
112 -- Description:
113 -- Given the source text of a compilation unit, print its post-processed
114 -- source text.
115 -- Input arguments:
116 -- source
117 -- The source text of the compilation unit
118 -- Exceptions:
119 -- ORA-24236: source text is empty.
120 -- ORA-24241: source text is wrapped.
121 -- ORA-06502: PL/SQL: numeric or value error: character string buffer
122 -- too small. A line is too long ( > 32767 bytes).
123
124 procedure print_post_processed_source(source varchar2);
125
126 -- Name:
127 -- print_post_processed_source
128 -- Description:
129 -- Given the source text of a compilation unit, print its post-processed
130 -- source text.
131 -- Input arguments:
132 -- source
133 -- Index-by table containing the source text of the compilation
134 -- unit. The source text is a concatenation of all the non-null
135 -- index-by table elements in ascending index order.
136 -- Exceptions:
137 -- ORA-24236: source text is empty.
138 -- ORA-24241: source text is wrapped.
139 -- ORA-06502: PL/SQL: numeric or value error: character string buffer
140 -- too small. A line is too long ( > 32767 bytes).
141 -- Notes:
142 -- The index-by table may contain holes. Null elements are ignored
143 -- when doing the concatenation.
144
145 procedure print_post_processed_source(source source_lines_t);
146
147 -- Name:
148 -- get_post_processed_source
149 -- Description:
150 -- Given a stored procedure, get its post-processed source text.
151 -- Input arguments:
152 -- object_type
153 -- Must be one of "PACKAGE", "PACKAGE BODY", "PROCEDURE", "FUNCTION",
154 -- "TYPE", "TYPE BODY", or "TRIGGER".
155 -- schema_name
156 -- The schema name. If NULL then use current schema.
157 -- object_name
158 -- The name of the object.
159 -- The object_type is always case insensitive. The schema_name or
160 -- object_name is case insensitive unless a quoted identifier is used.
161 -- RETURNS:
162 -- Index-by table containing the lines of the post-processed source
163 -- text starting from index 1. Newline characters are not removed.
164 -- Each line in the post-processed source text is mapped to a row
165 -- in the index-by table. In the post-processed source, unselected
166 -- text will have blank lines.
167 -- Exceptions:
168 -- ORA-24234: insufficient privileges or object does not exist.
169 -- ORA-24235: bad value for object type. Should be one of PACKAGE,
170 -- PACKAGE BODY, PROCEDURE, FUNCTION, TYPE, TYPE BODY, or TRIGGER.
171 -- ORA-00931: missing identifier. The object_name should not be null.
172 -- ORA-06502: PL/SQL: numeric or value error: character string buffer
173 -- too small. A line is too long ( > 32767 bytes).
174
175 function get_post_processed_source(object_type varchar2,
176 schema_name varchar2,
177 object_name varchar2)
178 return source_lines_t;
179
180 -- Name:
181 -- get_post_processed_source
182 -- Description:
183 -- Given the source text of a compilation unit, get its post-processed
184 -- source text.
185 -- Input arguments:
186 -- source
187 -- The source text of a compilation unit
188 -- RETURNS:
189 -- Index-by table containing the lines of the post-processed source
190 -- text starting from index 1. Newline characters are not removed.
191 -- Each line in the post-processed source text is mapped to a row
192 -- in the index-by table. In the post-processed source, unselected
193 -- text will have blank lines.
194 -- Exceptions:
195 -- ORA-24236: source text is empty.
196 -- ORA-24241: source text is wrapped.
197 -- ORA-06502: PL/SQL: numeric or value error: character string buffer
198 -- too small. A line is too long ( > 32767 bytes).
199
200 function get_post_processed_source(source varchar2)
201 return source_lines_t;
202
203 -- Name:
204 -- get_post_processed_source
205 -- Description:
206 -- Given the source text of a compilation unit, get its post-processed
207 -- source text.
208 -- Input arguments:
209 -- source
210 -- Index-by table containing the source text of the compilation unit
211 -- RETURNS:
212 -- Index-by table containing the lines of the post-processed source
213 -- text starting from index 1. Newline characters are not removed.
214 -- Each line in the post-processed source text is mapped to a row
215 -- in the index-by table. In the post-processed source, unselected
216 -- text will have blank lines.
217 -- Exceptions:
218 -- ORA-24236: source text is empty.
219 -- ORA-24241: source text is wrapped.
220 -- ORA-06502: PL/SQL: numeric or value error: character string buffer
221 -- too small. A line is too long ( > 32767 bytes).
222
223 function get_post_processed_source(source source_lines_t)
224 return source_lines_t;
225
226 end;