有没有办法在变量中传递值列表并在IN()语句中使用它来检查传入的值列表中的字段?
我唯一能想到的是这样的事情:
SELECT
field_name
WHERE
(SELECT INSTR(@variable_list, field_name))>0
感谢。
答案 0 :(得分:1)
TD14支持一个名为STRTOK_SPLIT_TO_TABLE的漂亮表函数:
REPLACE MACRO testmac(param VARCHAR(1000)) AS
(
SELECT * FROM dbc.DatabasesV AS db
JOIN
(
SELECT token AS DatabaseName, tokennum
FROM TABLE (STRTOK_SPLIT_TO_TABLE(1, :param, ',')
RETURNS (outkey INTEGER, -- usually the PK of the table, here it's just a dummy
tokennum INTEGER, -- order of the token within the param string
token VARCHAR(128) CHARACTER SET UNICODE)
) AS d
) AS dt
ON db.DatabaseName = dt.DatabaseName
ORDER BY tokennum;
);
EXEC testmac('dbc,systemfe,syslib');