CREATE OR REPLACE PROCEDURE dummy_proc
AS
CURSOR dummy_cur is
SELECT dummy AS dummy_alias1, dummy AS dummy_alias2,dummy dummy_alias3
, dummy AS dummy_alias4
, dummy dummy_alias5
,dummy dummy_alias6
,dummy dummy_alias7
FROM DUAL;
BEGIN
NULL;
END;
-- PROCEDURE DUMMY_PROC compiled
WITH all_src AS
(
SELECT owner, name, type, line, text
FROM all_source
WHERE owner = USER
AND type = 'PROCEDURE'
AND name = 'DUMMY_PROC'
)
, conditions AS
(
SELECT line AS con_start
, LEAD(line) OVER (PARTITION BY name ORDER BY line) AS con_end
FROM all_src
WHERE (INSTR(UPPER(text), 'SELECT') > 0 OR INSTR(UPPER(text), 'FROM') > 0)
)
, one_line AS
(
SELECT LISTAGG(text, ' ') WITHIN GROUP (ORDER BY line) AS select_line
FROM all_src
WHERE EXISTS
(
SELECT 1
FROM conditions
WHERE line >= con_start
AND line < con_end
)
)
SELECT REGEXP_REPLACE
(
REGEXP_SUBSTR(select_line, '\w+(\s+\,|\,|$)', 1, 1) || ' ' ||
REGEXP_SUBSTR(select_line, '\w+(\s+\,|\,|$)', 1, 2) || ' ' ||
REGEXP_SUBSTR(select_line, '\w+(\s+\,|\,|$)', 1, 3) || ' ' ||
REGEXP_SUBSTR(select_line, '\w+(\s+\,|\,|$)', 1, 4) || ' ' ||
REGEXP_SUBSTR(select_line, '\w+(\s+\,|\,|$)', 1, 5) || ' ' ||
REGEXP_SUBSTR(select_line, '\w+(\s+\,|\,|$)', 1, 6) || ' ' ||
REGEXP_SUBSTR(select_line, '\w+(\s+\,|\,|$)', 1, 7)
-- REGEXP_SUBSTR(select_line, '\w+(\s+\,|\,|$)', 1, 8)
-- REGEXP_SUBSTR(select_line, '\w+(\s+\,|\,|$)', 1, 9)
, '\s+\,\s+'
, ', '
) AS r_substr
FROM one_line
;
-- dummy_alias1, dummy_alias2, dummy_alias3, dummy_alias4, dummy_alias5, dummy_alias6, dummy_alias7