-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathstmtid.sql
More file actions
89 lines (75 loc) · 2.56 KB
/
stmtid.sql
File metadata and controls
89 lines (75 loc) · 2.56 KB
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
rollback;
set serveroutput on buffer 1000000000 echo on verify on feedback on pause off
set termout off
spool stmtid_before
set lines 100 long 5000
SELECT *
FROM ps_sqlstmt_tbl
WHERE pgm_name like 'GP%'
ORDER BY 1,2,3
;
spool off
set termout on
spool stmtid
DECLARE
CURSOR stmt_cursor IS
SELECT *
FROM ps_sqlstmt_tbl;
c_stmt stmt_cursor%ROWTYPE;
l_stmt_text VARCHAR2(32767); /*for stmt text so can use text functions*/
l_stmt_id VARCHAR2(18); /*PS stmt ID string*/
l_len INTEGER; /*length of stmt text*/
l_spcpos INTEGER; /*postition of first space*/
l_compos INTEGER; /*postition of first comment*/
l_compos2 INTEGER; /*end of first comment*/
l_idpos INTEGER; /*postition of statement id*/
BEGIN
OPEN stmt_cursor;
LOOP
FETCH stmt_cursor INTO c_stmt;
EXIT WHEN stmt_cursor%NOTFOUND;
l_stmt_id := c_stmt.pgm_name||'_'||c_stmt.stmt_type
||'_'||c_stmt.stmt_name;
l_stmt_text := c_stmt.stmt_text;
l_spcpos := instr(l_stmt_text,' ');
l_compos := instr(l_stmt_text,'/*');
l_compos2 := instr(l_stmt_text,'*/');
l_idpos := instr(l_stmt_text,l_stmt_id);
-- sys.dbms_output.put_line(l_stmt_id);
-- sys.dbms_output.put_line(substr(l_stmt_text,1,100));
-- sys.dbms_output.put_line('Space at '||l_spcpos);
-- sys.dbms_output.put_line('Comment at '||l_compos);
-- sys.dbms_output.put_line('Comment End at '||l_compos2);
-- sys.dbms_output.put_line('ID at '||l_idpos);
IF (l_idpos = 0 AND l_spcpos > 0 AND LENGTH(l_stmt_text)<=32000) THEN
/*no id comment in string and its not too long so add one*/
IF (l_compos = 0) THEN /*no comment exists*/
l_stmt_text := SUBSTR(l_stmt_text,1,l_spcpos) ||'/*'||
l_stmt_id||'*/'||SUBSTR(l_stmt_text,l_spcpos);
ELSE /*insert into existing comment*/
l_stmt_text := SUBSTR(l_stmt_text,1,l_compos2-1)||
' '||l_stmt_id||SUBSTR(l_stmt_text,l_compos2);
END IF;
UPDATE ps_sqlstmt_tbl
SET stmt_text = l_stmt_text
WHERE pgm_name = c_stmt.pgm_name
AND stmt_type = c_stmt.stmt_type
AND stmt_name = c_stmt.stmt_name;
-- sys.dbms_output.put_line(substr(l_stmt_text,1,100));
END IF;
END LOOP;
CLOSE stmt_cursor;
END;
/
show errors
spool off
set termout off
spool stmtid_after
set lines 100 long 5000
SELECT *
FROM ps_sqlstmt_tbl
WHERE pgm_name like 'GP%'
ORDER BY 1,2,3
;
set termout on
spool off