有没有办法只获取存储过程的select语句中使用的别名?我想使用select语句创建实体。
示例:
procedure Getnames(namerecords out Sys_refcursors)
as
begin
open namerecords for
select
N.First_name FirstName,
N.SecondName Secondname
from Names
End Getnames;
我希望仅通过传递存储过程名称来获取Firstname
,secondname
。
是否有存储此信息的系统表?
答案 0 :(得分:1)
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
答案 1 :(得分:0)
我猜答案是
select * from all_source where name='YOUR_SP'
。
但是你应该做一些文本处理来找到别名,并且程序应该具有相同的格式。