1

有没有办法只获取存储过程的 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因此只传递存储过程名称。

是否有存储此信息的系统表?

4

2 回答 2

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
于 2013-06-12T09:17:55.067 回答
0

我想答案是 select * from all_source where name='YOUR_SP'

但是您应该进行一些文本处理以查找别名,并且程序应该具有相同的格式。

于 2013-06-12T07:31:08.967 回答