问题描述
像Oracle一样,DB2支持存储过程中的参数默认值。 Oracle语法:
Like Oracle, DB2 supports parameter defaults in stored procedures. Oracle syntax:
CREATE OR REPLACE PROCEDURE p_default (
p_in_number IN number := 0,
p_out_number OUT number,
p_in_varchar IN varchar2 := '0',
p_out_varchar OUT varchar2,
p_in_date IN date := date '1981-07-10',
p_out_date OUT date
)
DB2语法:
CREATE PROCEDURE p_default (
IN p_in_number INTEGER DEFAULT(0),
OUT p_out_number INTEGER,
IN p_in_varchar VARCHAR(10) DEFAULT('0'),
OUT p_out_varchar VARCHAR(10),
IN p_in_date DATE DEFAULT('1981-07-10'),
OUT p_out_date DATE
)
使用Oracle,我可以使用此查询发现默认值:
With Oracle, I can discover defaults using this query:
SELECT argument_name, defaulted FROM all_arguments WHERE object_id = :proc_id
我如何发现这个在DB2中从 SYSCAT
表中选择s?我在 SYSCAT.PROCPARMS
或 SYSCAT.FUNCPARMS
中看不到任何有用的列。注意,我不介意从 SYSPROC
中调用任何存储过程,如果这样的过程存在...
How can I discover this in DB2 selecting from SYSCAT
tables? I don't see any useful column in SYSCAT.PROCPARMS
or SYSCAT.FUNCPARMS
. Note, I don't mind calling any stored procedure from SYSPROC
if such a procedure exists...
注意,我已经问过关于SQL Server的类似问题:
Note, I have asked as similar question about SQL Server:
推荐答案
(这假设您正在寻找DB2 Linux / Unix / Windows上的信息,其他平台可能会有所不同)
(This assumes you're looking for the information on DB2 Linux/Unix/Windows, it may vary for other platforms)
您可以使用目录视图以查找此信息。它列出了函数可以接受的所有参数类型(如果过程有多个签名,则可以有多个行),如果适用,它们的默认值(在aptly-named DEFAULT
列)。如果未提供默认值,该列将为 NULL
。
You can use the SYSCAT.ROUTINEPARMS
catalog view to find this information. It lists all the parameter types that the function can accept (there can be multiple rows if the procedure has multiple signatures), and if applicable, their default (in the aptly-named DEFAULT
column). If a default is not supplied, that column will be NULL
.
例如,如果您想查看输入参数为(具有可选参数),您可以使用此查询:
For example, if you wanted to see the input parameters for SYSIBMADM.SUBMIT
(which has optional parameters), you could use this query:
SELECT *
FROM SYSCAT.ROUTINEPARMS
WHERE ROUTINESCHEMA='SYSIBMADM'
AND ROUTINENAME ='SUBMIT'
AND ROWTYPE IN ('B', 'P')
ROWTYPE
的 B
允许输入和输出变量,而 P
仅用于输入。其他类型在我上面链接的信息中心文档中涵盖。
ROWTYPE
of B
allows for both input and output variables, and P
is for input-only. The other types are covered in the Info Center doc I linked above.
这篇关于使用SYSCAT表查找DB2过程的默认参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!