简体   繁体   English

如何用一条语句从Oracle数据库中选择所有存储过程?

[英]How to select all the stored procedures from Oracle database with one statement?

I want to view all the stored procedure implementations owned by fooUser in an Oracle database. 我想查看Oracle数据库中fooUser拥有的所有存储过程实现。

By using rownum , I am able to do this for the first procedure in dba_objects table, but there are many procedures in dba_objects table owned by fooUser . 通过使用rownum ,我可以对dba_objects表中的第一个过程执行此操作,但是dba_objects拥有的dba_objects表中有许多过程。

I do not want to write a stored procedure to achieve this, I want to do this with one SQL statement. 我不想编写存储过程来实现此目的,我想使用一个SQL语句来做到这一点。

Query to get the first stored procedure implementation: 查询以获取第一个存储过程的实现:

SELECT 
    line, text
FROM 
    dba_source
WHERE
    name = (SELECT object_name 
            FROM dba_objects 
            WHERE object_type = 'PROCEDURE' 
              AND owner = 'fooUser' AND rownum = 1) 
    AND type = 'PROCEDURE'
ORDER BY 
    line

to get source of procedure you can use dbms_metadata.get_ddl 要获取过程源,可以使用dbms_metadata.get_ddl

see documentation here dbms_metadata 在此处查看文档dbms_metadata

for example script below returns you list of procedures and source for each procedure where owner is usr1 例如,下面的脚本为您返回所有者为usr1每个过程的过程和源列表

select object_name
     , dbms_metadata.get_ddl(object_type,object_name) from dba_procedures
  where owner = 'USR1'
    and object_type = 'PROCEDURE'

OR 要么

if you need just line-by-line text for all procedures 如果您仅需要所有过程的逐行文本

SELECT line, text
FROM dba_source
WHERE owner = 'SCM'
  AND type = 'PROCEDURE'
ORDER BY name, line

try this: 尝试这个:

SELECT line, text
FROM dba_source
WHERE owner = ?
  AND name = ?
  AND type = 'PROCEDURE'
ORDER BY line

update #1: 更新#1:

SELECT line, text
FROM dba_source
WHERE owner = 'foouser'
  AND type = 'PROCEDURE'
ORDER BY line

update #2: 更新#2:

   SELECT line, text, name
    FROM dba_source
    WHERE owner = 'foouser'
      AND type = 'PROCEDURE'
    ORDER BY name, line

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM