Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a stored procedure exist?

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 type='PROCEDURE' 
   and name='my_stored_procedure.' 

Is there any other way to check if a procedure exists?

Edited to add:

Before posting SQL Server ways, please I'm looking for ORACLE ways.

like image 352
Paulo Santos Avatar asked Apr 19 '11 19:04

Paulo Santos


People also ask

How do I find a stored procedure?

In the Object Explorer in SQL Server Management Studio, go to the database and expand it. Expand the Programmability folder. Right Click the Stored Procedures folder. From the right-click menu, select Filter in the right-click menu.


2 Answers

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'
like image 190
Chandu Avatar answered Oct 05 '22 19:10

Chandu


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.

like image 35
ik_zelf Avatar answered Oct 05 '22 18:10

ik_zelf