Teradata variable with list of values

后端 未结 1 1123
北荒
北荒 2021-01-28 07:08

Is there a way to pass a list of values in a variable and use that in an IN() statement to check a field against the passed in list of values?

The only thing I can think

相关标签:
1条回答
  • 2021-01-28 07:36

    TD14 supports a nice table function called 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');
    
    0 讨论(0)
提交回复
热议问题