我有一个非常简单的存储过程,可以根据我的架构和表参数查找特定架构中的表。
问题是存储过程返回表的所有行。
有什么想法吗?提前致谢。存储过程如下。
CREATE OR REPLACE PROCEDURE FINDTABLECOLUMNS
(IN SCHEMA VARCHAR(25), IN TABLE_NAME VARCHAR(25))
LANGUAGE SQL
READS SQL DATA
RESULT SETS 1
BEGIN
DECLARE COLUMN_TABLE_LIST CURSOR WITH RETURN TO CALLER FOR
SELECT
ROW_NUMBER ( ) OVER ( ORDER BY TABLE_NAME , ORDINAL_POSITION ) AS #
,TABLE_NAME
,COLUMN_NAME
,SYSTEM_COLUMN_NAME
,DATA_TYPE
,LENGTH
,COLUMN_TEXT
FROM QSYS2 . SYSCOLUMNS
WHERE TABLE_SCHEMA = UPPER ( SCHEMA ) AND TABLE_NAME = UPPER ( TABLE_NAME )
FOR READ ONLY ;
OPEN COLUMN_TABLE_LIST ;
END
答案 0 :(得分:2)
我认为这是因为columnname和parametername是相同的。你可以解决它:
CREATE OR REPLACE PROCEDURE FINDTABLECOLUMNS
(IN SCHEMA VARCHAR(25), IN TABLE_NAME_PAR VARCHAR(25))
LANGUAGE SQL
READS SQL DATA
RESULT SETS 1
BEGIN
DECLARE COLUMN_TABLE_LIST CURSOR WITH RETURN TO CALLER FOR
SELECT
ROW_NUMBER ( ) OVER ( ORDER BY TABLE_NAME , ORDINAL_POSITION ) AS #
,TABLE_NAME
,COLUMN_NAME
,SYSTEM_COLUMN_NAME
,DATA_TYPE
,LENGTH
,COLUMN_TEXT
FROM QSYS2 . SYSCOLUMNS
WHERE TABLE_SCHEMA = UPPER ( SCHEMA ) AND TABLE_NAME = UPPER ( TABLE_NAME_PAR )
FOR READ ONLY ;
OPEN COLUMN_TABLE_LIST ;
END