获取程序依赖sybase的查询/过程

时间:2016-06-01 12:51:55

标签: sybase

我正在搜索一个查询/程序,它给我一个过程的所有依赖(结果类似于sp_depends)

程序proc1中的示例,它执行proc2,proc3,          在过程proc2中,它执行xproc1,xproc2

所以我希望我的输出像

proc1 -> proc2 -> xproc1 ->xproc2
proc1 -> proc3

编辑:

我创建了以下程序,但是关于它们的问题它给了我以下错误

------------------------ Execute ------------------------
Maximum stored procedure nesting level exceeded (limit 60). Please use sp_configure to increase the 'max nesting level'.
return status = -6

也是在限制光标计数之后(如果你仔细阅读了程序,你会注意到计数,所以我稍后修改了程序以指定我有多少窝来避免错误而我确实避免了它)结果缺少,我没有得到所有的程序依赖,我说我没有得到所有的程序依赖,我虽然调查和检查syscomments并选择in的程序问题取决于sysdepends它似乎sybase doenst给予所有依赖。我不知道。你有办法帮助我获得所有依赖吗?

CREATE TABLE dbo.PROC_HIERARCHY
( PROC_PATH VARCHAR(4000) NULL
)
GO

CREATE PROCEDURE dbo.PROC_DEP_REC
    @PROC_ID        INTEGER,
    @PATH           VARCHAR(4000) OUTPUT
AS
BEGIN
    SET NOCOUNT ON

    DECLARE @CURR_ID        INTEGER
    DECLARE @CURR_NAME      VARCHAR(40)
    DECLARE @ROW_COUNT      NUMERIC(12)
    DECLARE @PATH_OUT       VARCHAR(4000)

    -- retrieve the children
    DECLARE CURS CURSOR FOR
    select distinct o2.name, o2.id
    from sysdepends d
        inner join sysobjects o
        on d.id = o.id
        inner join sysobjects o2
        on d.depid = o2.id
    where o.type = 'P'  
        and o2.type = 'P'
        and o.id = @PROC_ID

    OPEN CURS
    FETCH CURS INTO @CURR_NAME, @CURR_ID

    WHILE (@@SQLSTATUS <> 2)
    BEGIN
        SELECT @PATH_OUT = @PATH + @CURR_NAME + '/'

        select @ROW_COUNT = COUNT(1)
        from sysdepends d
            inner join sysobjects o
            on d.id = o.id
            inner join sysobjects o2
            on d.depid = o2.id
        where o.type = 'P'  
            and o2.type = 'P'
            and o.id = @CURR_ID

        IF (@ROW_COUNT > 0)
            EXEC PROC_DEP_REC @CURR_ID, @PATH_OUT OUTPUT
        ELSE
            BEGIN
                IF (RIGHT(@PATH_OUT, 1) = '/')
                    SELECT @PATH_OUT = LEFT(@PATH_OUT, LEN(@PATH_OUT) - 1)

                INSERT INTO PROC_HIERARCHY VALUES (@PATH_OUT)
            END

        FETCH CURS INTO @CURR_NAME, @CURR_ID
    END

    CLOSE CURS
    DEALLOCATE CURS

    IF (RIGHT(@PATH_OUT, 1) = '/')
        SELECT @PATH = SUBSTRING(@PATH_OUT, 1, LEN(@PATH_OUT) - CHARINDEX('/', REVERSE(@PATH_OUT))) 
END

GO

CREATE PROCEDURE dbo.PROC_DEP
AS
BEGIN
    SET NOCOUNT ON

    DECLARE @CURR_ID        INTEGER
    DECLARE @CURR_NAME      VARCHAR(40)
    DECLARE @PATH           VARCHAR(4000)

    DECLARE CURS CURSOR FOR
    select distinct o.name, o.id
    from sysdepends d
        inner join sysobjects o
        on d.id = o.id
        inner join sysobjects o2
        on d.depid = o2.id
    where o.type = 'P'  
        and o2.type = 'P'

    OPEN CURS
    FETCH CURS INTO @CURR_NAME, @CURR_ID

    WHILE (@@SQLSTATUS <> 2)
    BEGIN
        SELECT @PATH = @CURR_NAME + '/'
        EXEC PROC_DEP_REC @CURR_ID, @PATH OUTPUT

        FETCH CURS INTO @CURR_NAME, @CURR_ID
    END

    CLOSE CURS
    DEALLOCATE CURS

    SELECT DISTINCT * 
    FROM PROC_HIERARCHY 
    ORDER BY PROC_PATH

END
GO

1 个答案:

答案 0 :(得分:1)

sp_depends本身的查询怎么样? 转到$ SYBASE / ASE-X_Y / scripts目录并找到installmaster文件(或WIndows上的instmstr)并查找sp_depends。 然后你只需要以不同的方式格式化输出,例如在最终结果集上运行游标循环。