带有值列表的 Teradata 变量
Teradata variable with list of values
有没有办法在变量中传递值列表并在 IN() 语句中使用它来根据传入的值列表检查字段?
我唯一能想到的是这样的:
SELECT
field_name
WHERE
(SELECT INSTR(@variable_list, field_name))>0
谢谢。
TD14 支持一个很好的 table 函数,叫做 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');
有没有办法在变量中传递值列表并在 IN() 语句中使用它来根据传入的值列表检查字段?
我唯一能想到的是这样的:
SELECT
field_name
WHERE
(SELECT INSTR(@variable_list, field_name))>0
谢谢。
TD14 支持一个很好的 table 函数,叫做 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');