Discover DB2 procedure default parameters using SYSCAT tables

时光毁灭记忆、已成空白 提交于 2019-12-12 03:11:47

问题


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 syntax:

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
)

With Oracle, I can discover defaults using this query:

SELECT argument_name, defaulted FROM all_arguments WHERE object_id = :proc_id

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...

Note, I have asked as similar question about SQL Server:

Discover SQL Server procedure default parameters using SYS or INFORMATION_SCHEMA tables


回答1:


(This assumes you're looking for the information on DB2 Linux/Unix/Windows, it may vary for other platforms)

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 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.



来源:https://stackoverflow.com/questions/9838076/discover-db2-procedure-default-parameters-using-syscat-tables

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!