如果在proc中某处出现文本字符串,如何在Sybase数据库中找到存储过程?我想看看db中的任何其他proc是否具有与我正在查看的那个类似的逻辑,并且我认为我有一个非常独特的搜索字符串(文字)
编辑:
我正在使用Sybase版本11.2
答案 0 :(得分:15)
Graeme答案的两个变体(所以这也不适用于11.2):
这也列出了sproc的名称,但如果文本出现多次,将为每个sproc返回多行:
select object_name(id),* from syscomments
where texttype = 0 and text like '%whatever%'
这只列出了一次:
select distinct object_name(id) from syscomments
where texttype = 0 and text like '%whatever%'
答案 1 :(得分:7)
在SQL Anywhere和Sybase IQ中:
select * from SYS.SYSPROCEDURE where proc_defn like '%whatever%'
我对ASE并不熟悉,但根据文档(可从sybooks.sybase.com获得),它类似于:
select * from syscomments where texttype = 0 and text like '%whatever%'
答案 2 :(得分:6)
select * from sysobjects where
id in ( select distinct (id) from syscomments where text like '%SearchTerm%')
and xtype = 'P'
答案 3 :(得分:5)
请记住,syscomments中的text列是varchar(255),因此一个大的过程可以包含syscomments中的许多行,因此,如果过程名称被拆分为2个文本行,则上述选择将找不到过程名称syscomments中。
我建议使用以下select,它将处理上述情况:
declare @text varchar(100)
select @text = "%whatever%"
select distinct o.name object
from sysobjects o,
syscomments c
where o.id=c.id
and o.type='P'
and (c.text like @text
or exists(
select 1 from syscomments c2
where c.id=c2.id
and c.colid+1=c2.colid
and right(c.text,100)+ substring(c2.text, 1, 100) like @text
)
)
order by 1
- 为此感到荣幸的是ASEisql
的创造者答案 4 :(得分:3)
select distinct object_name(syscomments.id) 'SearchText', syscomments.id from syscomments ,sysobjects
where texttype = 0 and text like '%SearchText%' and syscomments.id=sysobjects.id and sysobjects.type='P'
答案 5 :(得分:0)
多行用于存储数据库对象的文本,该值可能跨越两行。所以更准确的答案是:
select distinct object_name(sc1.id)
from syscomments sc1
left join syscomments sc2
on (sc2.id = sc1.id and
sc2.number = sc1.number and
sc2.colid2 = sc1.colid2 + ((sc1.colid + 1) / 32768) and
sc2.colid = (sc1.colid + 1) % 32768)
where
sc1.texttype = 0 and
sc2.texttype = 0 and
lower(sc1.text + sc2.text) like lower('%' || @textSearched || '%')