我正在尝试在PDI表输入中的WHERE COLUMN IN查询中替换逗号分隔的字符串。我有一个字符串查询=(“ car”,“ bike”),我要替换为SELECT * FROM车辆,其中?。
中的项目我试图将此字符串传递给?在表输入中使用替换变量,并从生成查询变量的上一步(设置变量)中获取。这种方式行不通,因为PDI在我的变量周围添加了“”,并且IN查询不起作用。
SELECT
item_id
, GROUP_CONCAT(DISTINCT name ORDER BY item_id, name SEPARATOR '", "') AS car_names
FROM testData
GROUP BY item_id
LIMIT 1
;
Modified Java Script Value:
var str = '';
var newtax = str.concat('(', '"', car_names, '"', ')');
// next step is to Set Variable
select
distinct name as 'car_name'
from vehicle
where name in '${query}'
union all
select "test1" as 'car_name'
from dual
union all
select "test2" as 'car_name'
from dual
union all
select "test3" as 'car_name'
from dual
limit 3
;```
expected result is
car
bike
test1
actual result:
2019/08/27 14:30:16 - hh.0 - Caused by: org.pentaho.di.core.exception.KettleDatabaseException:
2019/08/27 14:30:16 - hh.0 - Error setting value #1 [String] on prepared statement
2019/08/27 14:30:16 - hh.0 - Parameter index out of range (1 > number of parameters, which is 0).
在这种情况下,我会以'car,bike'的形式获得列表(例如您从group_concat()
获得的内容,然后使用find_in_set()
代替where ... in (...)
select
distinct name as 'car_name'
from vehicle
where find_in_set(name, ?)