Teradata REGEXP_SPLIT_TO_TABLE输入参数

时间:2016-09-26 17:40:03

标签: function teradata

我希望能够在CTE中定义输入参数,然后在REGEXP_SPLIT_TO_TABLE函数中使用它,如下所示:

WITH PARAMS (INPUT_PARAMS) AS
(SELECT
    '?InputParams' AS INPUT_PARAMS
)
SELECT
    TEST_TABLE.SPLIT_PARAMS
FROM
    TABLE (REGEXP_SPLIT_TO_TABLE(1, PARAMS.INPUT_PARAMS, '\|', 'i')
        RETURNS (outkey INTEGER, TOKENNUM INTEGER, SPLIT_PARAMS VARCHAR(8192) CHARACTER SET UNICODE)) AS TEST_TABLE
    CROSS JOIN PARAMS

然而,这会产生以下错误:

  

SELECT失败。 [3706]语法错误:不支持联接表   与表运算符或表调用的函数结合使用   变量输入参数。

将参数放在函数中,如下所示:

SELECT
    TEST_TABLE.SPLIT_PARAMS
FROM
    TABLE (REGEXP_SPLIT_TO_TABLE(1, '?InputParams', '\|', 'i') --
        RETURNS (outkey INTEGER, TOKENNUM INTEGER, SPLIT_PARAMS VARCHAR(8192) CHARACTER SET UNICODE)) AS TEST_TABLE

但我想知道是否有办法做更像上面第一个例子的事情。

1 个答案:

答案 0 :(得分:2)

此函数不允许使用JOIN语法,但您可以执行旧式连接:

WITH PARAMS (INPUT_PARAMS) AS
(SELECT
    '?InputParams' AS INPUT_PARAMS
)
SELECT
    TEST_TABLE.SPLIT_PARAMS
FROM
    TABLE (REGEXP_SPLIT_TO_TABLE(1, PARAMS.INPUT_PARAMS, '\|', 'i')
        RETURNS (outkey INTEGER, TOKENNUM INTEGER, SPLIT_PARAMS VARCHAR(8192) CHARACTER SET UNICODE)) AS TEST_TABLE
    ,PARAMS

事实上,你根本不需要加入:

WITH PARAMS (INPUT_PARAMS) AS
(SELECT
    '?InputParams' AS INPUT_PARAMS
)
SELECT
    TEST_TABLE.SPLIT_PARAMS
FROM
    TABLE (REGEXP_SPLIT_TO_TABLE(1, PARAMS.INPUT_PARAMS, '\|', 'i')
        RETURNS (outkey INTEGER, TOKENNUM INTEGER, SPLIT_PARAMS VARCHAR(8192) CHARACTER SET UNICODE)) AS TEST_TABLE

由于您不使用正则表达式,因此您也可以切换到STRTOK_SPLIT_TO_TABLE

WITH PARAMS (INPUT_PARAMS) AS
(SELECT
    '?InputParams' AS INPUT_PARAMS
)
SELECT
    TEST_TABLE.SPLIT_PARAMS
FROM
    TABLE (StrTok_Split_To_Table(1, PARAMS.INPUT_PARAMS, '\|')
        RETURNS (outkey INTEGER, TOKENNUM INTEGER, SPLIT_PARAMS VARCHAR(8192) CHARACTER SET Unicode)) AS TEST_TABLE