在DB2 for Z / OS的IN CLAUSE中以逗号分隔的变量

时间:2017-04-06 13:24:56

标签: db2

我有一个SP,其中我有一个如下所述的In子句 value1是Int,Variable1是varchar 假设SP开始了 Variable1 =(value1,value2,value3) - 从另一个表中获取

从tableA中选择*,其中Column1位于(Variable1)。

上述声明无效,需要解决此问题,请帮忙

1 个答案:

答案 0 :(得分:0)

以下是使用XML列表选择任意数量值的小例子:

SELECT * FROM "tableA"
WHERE "Column1" IN (
SELECT * FROM
XMLTABLE('$X/set/row' PASSING XMLPARSE('
<set>
<row item="1"/>
<row item="2"/>
<row item="3"/>
<!-- add as many "row" as you need here -->
</set>
')
AS "X"
COLUMNS 
"item" INT PATH '@item'
) AS X
)

然后您可以参数化查询,其中?XML类型的参数

SELECT * FROM "tableA"
WHERE "Column1" IN (
  SELECT * FROM 
  XMLTABLE('$X/set/row' PASSING ? AS "X" COLUMNS "item" INT PATH '@item') AS X
)