我创建了这个程序来获取数据库中的所有过程生成一个文档(通过注释)并列出所有" in"和" out" params - 这很好,它完美无缺!
我面临的问题是,在我构建的应用程序中,我想选择其中一个程序(所以当用户点击此列表中的一个项目时)并输出其详细信息(创建第二个)处理这个的程序不是一个选项)
这是原始代码(忽略p ***** - 这是故意隐藏的(但从未在过程中使用 - 它用于记录)):
ALTER PROCEDURE "USER"."NetDefineProcs"
/* DOC
Everything between the DOC tags are used to generate the user document.
*/
( in "p*****" char(20), in "pSearchTerm" long varchar, in "pSelectOne" char(1) default null)
result( "proccessName" long varchar, "Doc" long varchar, "paramName" long varchar,"paramIO" long varchar,"paramDefault" long varchar,"paramType" long varchar )
begin
SELECT "proc_name" as "proccessName",
(SELECT substr(source, charindex('/* DOC', source)+6, charindex('*/', source) - charindex('/* DOC', source)-6 ) FROM "sys"."sysprocedure" where "proc_name" = "proccessName" AND charindex('/* DOC', source) > 0) as "Doc",
"LIST"("parm_name" order by "parm_type" asc,"parm_id" asc) as "paramName",
"LIST"("parm_type" order by "parm_type" asc,"parm_id" asc) as "paramIO",
"LIST"("isnull"("default",'null') order by "parm_type" asc,"parm_id" asc) as "paramDefault",
"LIST"("isnull"("domain_name",'null') order by "parm_type" asc,"parm_id" asc) as "paramType"
from "sys"."sysprocedure" as "pr" key join "SYS"."SYSPROCPARM" as "pa" key join "SYS"."SYSDOMAIN"
-- Below code requires sybase 16 - temporary version 11 friendly version above
-- "LIST"("isnull"("base_type_str",'null') order by "parm_type" asc,"parm_id" asc) as "paramType"
-- from "sys"."sysprocedure" as "pr" key join "SYS"."SYSPROCPARM" as "pa" --where pr.proc_name = o.proc_name ;
-- WHERE "proc_name" like 'net%' AND "proc_name" like '%' + pSearchTerm + '%'
WHERE "proc_name" = pSearchTerm OR "proc_name" like 'net%' AND "proc_name" like '%' + pSearchTerm + '%'
group by "proc_name"
order by 1 asc
end
上面的代码适用于获取所有这些代码,现在这里是我写的代码,试图只获取一个
ALTER PROCEDURE "USER"."NetDefineProcs"
/* DOC
Everything between the DOC tags are used to generate the user document.
*/
( in "p*****" char(20), char(20), in "pSearchTerm" long varchar, in "pSelectOne" char(1) default null)
result( "proccessName" long varchar, "Doc" long varchar, "paramName" long varchar,"paramIO" long varchar,"paramDefault" long varchar,"paramType" long varchar )
begin
CASE
WHEN pSelectOne = '1' THEN SELECT FIRST "proc_name" as "proccessName",
ELSE SELECT "proc_name" as "proccessName",
END
(SELECT substr(source, charindex('/* DOC', source)+6, charindex('*/', source) - charindex('/* DOC', source)-6 ) FROM "sys"."sysprocedure" where "proc_name" = "proccessName" AND charindex('/* DOC', source) > 0) as "Doc",
"LIST"("parm_name" order by "parm_type" asc,"parm_id" asc) as "paramName",
"LIST"("parm_type" order by "parm_type" asc,"parm_id" asc) as "paramIO",
"LIST"("isnull"("default",'null') order by "parm_type" asc,"parm_id" asc) as "paramDefault",
"LIST"("isnull"("domain_name",'null') order by "parm_type" asc,"parm_id" asc) as "paramType"
from "sys"."sysprocedure" as "pr" key join "SYS"."SYSPROCPARM" as "pa" key join "SYS"."SYSDOMAIN"
-- Below code requires sybase 16 - temporary version 11 friendly version above
-- "LIST"("isnull"("base_type_str",'null') order by "parm_type" asc,"parm_id" asc) as "paramType"
-- from "sys"."sysprocedure" as "pr" key join "SYS"."SYSPROCPARM" as "pa" --where pr.proc_name = o.proc_name ;
-- WHERE "proc_name" like 'net%' AND "proc_name" like '%' + pSearchTerm + '%'
WHERE "proc_name" = pSearchTerm OR "proc_name" like 'net%' AND "proc_name" like '%' + pSearchTerm + '%'
group by "proc_name"
order by 1 asc
end
现在我知道有一个语法错误,因为select语句有尾随''但是,有什么方法可以让我有类似于我试图实现的东西,而不会让它变得凌乱吗?
答案 0 :(得分:0)
解决了!
将此添加到" in" PARAMS
in "pSelectOne" char(1) default null
并将where子句更改为
WHERE (pSelectOne IS NOT NULL and "proc_name" = pSearchTerm) or (pSelectOne IS NULL and "proc_name" like 'net%' AND "proc_name" like '%' + pSearchTerm + '%')
它有效。