Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find Sybase stored procedure in db given a text string that appears in the proc

How do I find a stored procedure in a Sybase database given a text string that appears somewhere in the proc? I want to see if any other proc in the db has similar logic to the one I'm looking at, and I think I have a pretty unique search string (literal)

Edit:

I'm using Sybase version 11.2

like image 412
Oskar Avatar asked Oct 30 '08 16:10

Oskar


2 Answers

Two variations on Graeme's answer (So this also won't work on 11.2):

This lists the name of the sproc too, but will return multiple rows for each sproc if the text appears several times:

select object_name(id),* from syscomments 
   where texttype = 0 and text like '%whatever%'

This lists each sproc just once:

select distinct object_name(id) from syscomments 
   where texttype = 0 and text like '%whatever%'
like image 131
AdamH Avatar answered Sep 27 '22 21:09

AdamH


In SQL Anywhere and Sybase IQ:

select * from SYS.SYSPROCEDURE where proc_defn like '%whatever%'

I'm not that familiar with ASE, but according to the docs (available from sybooks.sybase.com), it's something like:

select * from syscomments where texttype = 0 and text like '%whatever%'
like image 43
Graeme Perrow Avatar answered Sep 27 '22 22:09

Graeme Perrow