-
Notifications
You must be signed in to change notification settings - Fork 16
/
P.pkb
398 lines (360 loc) · 8.38 KB
/
P.pkb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
CREATE OR REPLACE PACKAGE BODY p
IS
/*----------------------------------------------------------------
|| PL/Vision Professional
||----------------------------------------------------------------
|| File: p.spb
|| Author: Steven Feuerstein
||
||
|| Copyright (C) 1996-2002 Quest Software
|| All rights reserved.
||
-----------------------------------------------------------------*/
c_pkg CONSTANT CHAR (1) := 'p';
c_max_dopl_line INTEGER := 255;
c_delim CONSTANT CHAR (3) := ' - ';
/* Flag that determines whether output should be displayed. */
v_show BOOLEAN := TRUE;
g_showtime BOOLEAN := FALSE;
g_lasttime INTEGER := NULL;
/* Private Variable for "linesep" */
v_linesep VARCHAR2 (100) := NULL;
/* Private Variable for "prefix" */
v_prefix VARCHAR2 (100) := c_prefix;
v_prefix_len INTEGER := 1;
v_linelen INTEGER := c_linelen;
/*------------------- Private Modules -------------------*/
PROCEDURE put_line (stg_in IN VARCHAR2)
IS
BEGIN
DBMS_OUTPUT.put_line (v_prefix || stg_in);
EXCEPTION
WHEN OTHERS
THEN
DBMS_OUTPUT.ENABLE (1000000);
DBMS_OUTPUT.put_line (v_prefix || stg_in);
END;
PROCEDURE display_line (show_in IN BOOLEAN, line_in IN VARCHAR2)
IS
BEGIN
IF v_show OR show_in
THEN
IF RTRIM (line_in) IS NULL
THEN
put_line ('');
ELSIF LTRIM (RTRIM (line_in)) = v_linesep
THEN
put_line ('');
ELSIF LENGTH (line_in) > linelen
THEN
put_line (SUBSTR (line_in, 1, linelen));
display_line (show_in
, SUBSTR (line_in, linelen + 1));
ELSE
put_line (line_in);
END IF;
END IF;
END;
/*--------------- Toggle Output Modules ---------------*/
PROCEDURE turn_on
IS
BEGIN
v_show := TRUE;
DBMS_OUTPUT.ENABLE (1000000);
END;
PROCEDURE turn_off
IS
BEGIN
v_show := FALSE;
END;
/* Body of Set for "linesep" */
PROCEDURE set_linesep (linesep_in IN VARCHAR2)
IS
BEGIN
v_linesep := linesep_in;
END set_linesep;
/* Body of Get for "linesep" */
FUNCTION linesep
RETURN VARCHAR2
IS
BEGIN
RETURN v_linesep;
END;
/* Body of Set for "prefix" */
PROCEDURE set_prefix (prefix_in IN VARCHAR2 := c_prefix)
IS
BEGIN
v_prefix := prefix_in;
v_prefix_len := LENGTH (prefix_in);
END set_prefix;
/* Body of Get for "prefix" */
FUNCTION prefix
RETURN VARCHAR2
IS
BEGIN
RETURN v_prefix;
END prefix;
/* Set line length before wrap */
PROCEDURE set_linelen (len IN INTEGER := c_linelen)
IS
BEGIN
v_linelen :=
LEAST (c_max_dopl_line
, GREATEST (NVL (len, c_linelen), 1)
);
END;
FUNCTION linelen
RETURN INTEGER
IS
BEGIN
RETURN v_linelen;
END;
/*------------------ The p.l Procedures ----------------*/
FUNCTION date_string (dt IN DATE, MASK IN VARCHAR2 := NULL)
RETURN VARCHAR2
IS
BEGIN
IF MASK IS NOT NULL
THEN
RETURN TO_CHAR (dt, MASK);
ELSE
RETURN TO_CHAR (dt);
END IF;
END;
FUNCTION bool_string (val IN boolean)
RETURN VARCHAR2
IS
BEGIN
IF val
THEN
RETURN 'TRUE';
ELSIF NOT val
THEN
RETURN 'FALSE';
ELSE
RETURN 'NULL';
END IF;
END;
PROCEDURE l (
dt IN DATE
, mask_in IN VARCHAR2 := NULL
, show_in IN BOOLEAN := FALSE
)
IS
BEGIN
display_line (show_in, date_string (dt, mask_in));
END;
PROCEDURE l (num IN NUMBER, show_in IN BOOLEAN := FALSE)
IS
BEGIN
display_line (show_in, TO_CHAR (num));
END;
PROCEDURE l (stg IN VARCHAR2, show_in IN BOOLEAN := FALSE)
IS
BEGIN
display_line (show_in, stg);
END;
PROCEDURE l (
stg IN VARCHAR2
, num IN NUMBER
, show_in IN BOOLEAN := FALSE
)
IS
BEGIN
display_line (show_in, stg || c_delim || TO_CHAR (num));
END;
PROCEDURE l (
stg IN VARCHAR2
, dt IN DATE
, mask_in IN VARCHAR2 := NULL
, show_in IN BOOLEAN := FALSE
)
IS
BEGIN
display_line (show_in
, stg || c_delim || date_string (dt, mask_in)
);
END;
PROCEDURE l (bool IN BOOLEAN, show_in IN BOOLEAN := FALSE)
IS
BEGIN
display_line (show_in, bool_string (bool));
END;
PROCEDURE l (
stg IN VARCHAR2
, bool IN BOOLEAN
, show_in IN BOOLEAN := FALSE
)
IS
BEGIN
display_line (show_in
, stg || c_delim || bool_string (bool)
);
END;
PROCEDURE l (
file_in IN UTL_FILE.file_type
, show_in IN BOOLEAN := FALSE
)
IS
BEGIN
display_line (show_in, TO_CHAR (file_in.ID));
END;
PROCEDURE l (
string_in IN VARCHAR2
, file_in IN UTL_FILE.file_type
, show_in IN BOOLEAN := FALSE
)
IS
BEGIN
l (string_in, file_in.ID, show_in);
END;
/* Additional overloadings */
PROCEDURE l (
num1 IN NUMBER
, num2 IN NUMBER
, show_in IN BOOLEAN := FALSE
)
IS
BEGIN
display_line (show_in
, TO_CHAR (num1) || c_delim || TO_CHAR (num2)
);
END;
PROCEDURE l (
str IN VARCHAR2
, num1 IN NUMBER
, num2 IN NUMBER
, show_in IN BOOLEAN := FALSE
)
IS
BEGIN
display_line (show_in
, str
|| c_delim
|| TO_CHAR (num1)
|| c_delim
|| TO_CHAR (num2)
);
END;
PROCEDURE l (
bool1 IN BOOLEAN
, bool2 IN BOOLEAN
, show_in IN BOOLEAN := FALSE
)
IS
BEGIN
display_line (show_in
, bool_string (bool1)
|| c_delim
|| bool_string (bool2)
);
END;
PROCEDURE l (
stg1 IN VARCHAR2
, stg2 IN VARCHAR2
, show_in IN BOOLEAN := FALSE
)
IS
BEGIN
display_line (show_in, stg1 || c_delim || stg2);
END;
PROCEDURE l (
dt1 IN DATE
, dt2 IN DATE
, mask_in IN VARCHAR2 := NULL
, show_in IN BOOLEAN := FALSE
)
IS
BEGIN
display_line (show_in
, date_string (dt1, mask_in)
|| c_delim
|| date_string (dt2, mask_in)
);
END;
PROCEDURE l (
num IN NUMBER
, dt IN DATE
, mask_in IN VARCHAR2 := NULL
, show_in IN BOOLEAN := FALSE
)
IS
BEGIN
display_line (show_in
, TO_CHAR (num)
|| c_delim
|| date_string (dt, mask_in)
);
END;
PROCEDURE l (
bool IN BOOLEAN
, num IN NUMBER
, show_in IN BOOLEAN := FALSE
)
IS
BEGIN
display_line (show_in
, bool_string (bool) || c_delim
|| TO_CHAR (num)
);
END;
PROCEDURE l (
bool IN BOOLEAN
, dt IN DATE
, mask_in IN VARCHAR2 := NULL
, show_in IN BOOLEAN := FALSE
)
IS
BEGIN
display_line (show_in
, bool_string (bool)
|| c_delim
|| date_string (dt, mask_in)
);
END;
PROCEDURE l (
bool IN BOOLEAN
, stg IN VARCHAR2
, show_in IN BOOLEAN := FALSE
)
IS
BEGIN
display_line (show_in
, stg || c_delim || bool_string (bool)
);
END;
PROCEDURE HELP (topic_in IN VARCHAR2 := NULL)
IS
BEGIN
p.l
('PLVhlp disabled; please check Knowledge Xpert for current documentation.'
); /* PLVhlp.plvshow (c_pkg, topic_in); */
END;
/* Show time stamp toggle. Default is NOSHOW. */
PROCEDURE showtime
IS
BEGIN
g_showtime := TRUE;
g_lasttime := NULL;
END;
PROCEDURE noshowtime
IS
BEGIN
g_showtime := TRUE;
g_lasttime := NULL;
END;
FUNCTION showing_time
RETURN BOOLEAN
IS
BEGIN
RETURN g_showtime;
END;
END p;
/
/*======================================================================
| Supplement to the fifth edition of Oracle PL/SQL Programming by Steven
| Feuerstein with Bill Pribyl, Copyright (c) 1997-2009 O'Reilly Media, Inc.
| To submit corrections or find more code samples visit
| http://oreilly.com/catalog/9780596514464/
*/