给定出现在 proc 中的文本字符串,在 db 中查找 Sybase 存储过程

发布于 2024-07-08 15:43:17 字数 149 浏览 13 评论 0原文

给定出现在存储过程中某处的文本字符串,如何在 Sybase 数据库中查找存储过程? 我想看看数据库中的任何其他过程是否与我正在查看的过程具有类似的逻辑,并且我认为我有一个非常独特的搜索字符串(文字)

编辑:

我正在使用 Sybase 版本 11.2

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

胡渣熟男 2024-07-15 15:43:17

Graeme 的答案有两个变体(所以这在 11.2 上也不起作用):

这也列出了存储过程的名称,但如果文本出现多次,将为每个存储过程返回多行:

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%'

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%'
‖放下 2024-07-15 15:43:17

在 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%'

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%'
柠檬心 2024-07-15 15:43:17

请记住,syscomments 中的文本列是 varchar(255),因此一个大过程可以由 syscomments 中的多行组成,因此,如果过程名称在 syscomments 中被拆分为 2 个文本行,则上述选择将找不到过程名称。

我建议使用以下选择,它将处理上述情况:

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 的创建者

Please remember, that text column in syscomments is varchar(255), so one big procedure can consist of many lines in syscomments, thus, the above selects will not find the procedure name if it has been splitted into 2 text rows in syscomments.

I suggest the following select, which will handle the above case:

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

-- kudos for this go to the creator of ASEisql

落花随流水 2024-07-15 15:43:17
select *  from sysobjects where 
    id in ( select distinct (id) from syscomments where text like '%SearchTerm%')
    and xtype = 'P'
select *  from sysobjects where 
    id in ( select distinct (id) from syscomments where text like '%SearchTerm%')
    and xtype = 'P'
完美的未来在梦里 2024-07-15 15:43:17
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'
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'
梅倚清风 2024-07-15 15:43:17

多行用于存储数据库对象的文本,该值可能跨两行。 所以更准确的答案是:

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 || '%')

Multiple rows are used to store text for database objects the value might be accross two rows. So the more accurate answer is:

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 || '%')
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文