How to check if a stored procedure exist?

后端 未结 6 1379
情书的邮戳
情书的邮戳 2020-12-30 09:58

I have searched the net and I\'ve found a post that uses the following snippet to check if a stored procedure exists:

select * 
  from USER_SOURCE 
 where ty         


        
相关标签:
6条回答
  • 2020-12-30 10:11

    select * from USER_SOURCE where type='PROCEDURE' and name='my_stored_procedure.'

    0 讨论(0)
  • 2020-12-30 10:15

    Alternatives:

    USER_PROCEDURES:

    SELECT *
      FROM USER_PROCEDURES
     WHERE object_name = 'MY_STORED_PROCEDURE'
    

    USER_OBJECTS:

    SELECT *
      FROM USER_OBJECTS
     WHERE object_type = 'PROCEDURE'
       AND object_name = 'MY_STORED_PROCEDURE'
    
    0 讨论(0)
  • 2020-12-30 10:21

    Execute the query below in SQL*PLUS, ODBC Test,...

    SELECT text FROM all_source WHERE name='MY_PROCEDURE' ORDER BY line

    where MY_PROCEDURE is the stored procedure name.

    Below is sample output:

    Get Data All: "TEXT" "PROCEDURE Usp_Get_Blob
    "(
    "P_DOC_ID INT,
    "P_DOC_TEXT OUT BLOB)
    "as
    "begin
    " select B1 into p_doc_text
    " from blobtest
    " where ID = p_doc_id;
    "end; "

    0 讨论(0)
  • 2020-12-30 10:21

    The only way to see if a procedure exists in the database is though querying DBA_OBJECTS. The disadvantage here is that only a dba has access to this view. Second best is using all_objects. ALL_OBJECTS shows you the objects for which you have somehow a privilege. USER_OBJECTS only shows you your own objects.

    0 讨论(0)
  • 2020-12-30 10:27

    Something that worked for me!

    SELECT text
    FROM all_source
    WHERE name = 'MY_SP_NAME'
    ORDER BY line;
    

    Alternatively you can try calling SP like this:

    CALL MY_SP_NAME();
    

    You might end up error like this, but that confirms you have SP defined there:

    OCI Statement Execution failure.ORA-06553: PLS-306: wrong number or types of arguments in call to 'MY_SP_NAME'
    
    0 讨论(0)
  • 2020-12-30 10:35

    I was not able to find stored procedure with any of the methods above.

    Reason: stored procedure was inside package. Oracle uses packages to gather several stored procedures in one module.

    0 讨论(0)
提交回复
热议问题