DB2 的动态 SQL

问题描述 投票:0回答:1

下面的 SQL 查询不会将列提取到 v_columns 中。当我打印 v_columns 时它总是 NULL

SET v_sql = 'SELECT LISTAGG(COLNAME , '','') WITHIN GROUP (ORDER BY COLNO) INTO :v_columns ' || 'FROM SYSCAT.COLUMNS ' || 'WHERE TABNAME = ''' || v_tableName || ''' AND COLNAME <> ''TOWID''';
sql database stored-procedures db2
1个回答
0
投票

区分大小写。

尝试:

SET v_sql = 'SELECT LISTAGG(COLNAME , '','') WITHIN GROUP (ORDER BY COLNO) INTO :v_columns ' || 'FROM SYSCAT.COLUMNS ' || 'WHERE UPPER(TABNAME) = UPPER(''' || v_tableName || ''') AND COLNAME <> ''TOWID''';
© www.soinside.com 2019 - 2024. All rights reserved.