在 where 子句中使用通配符的 Snowflake 函数参数

Snowflake function parameters with wildcard in where clause

您知道为什么以下函数调用在参数内使用通配符时不起作用吗?

CREATE OR REPLACE FUNCTION ABC("CUSTCODE" VARCHAR, "CUSTNAME" VARCHAR)
RETURNS TABLE ("CUSTOMER_CODE" VARCHAR, CUSTOMERNAME VARCHAR)
LANGUAGE SQL
AS $$                                  
   SELECT  CUSTOMER_CODE, CUSTOMERNAME FROM DIM_CUSTOMER
    WHERE  CUSTNAME is null AND CUSTOMER_CODE ILIKE '%CUSTCODE%'
$$;

我没有收到任何错误,但也没有找到任何记录

似乎不​​喜欢喜欢的“%CUSTCODE%”位

谢谢

您的代码块内有单引号 ',但代码块标有单引号。所以以太交换成双倍美元 $$

CREATE OR REPLACE FUNCTION ABC("CUSTCODE" VARCHAR)
RETURNS TABLE ("CUSTOMER_CODE" VARCHAR, CUSTOMERNAME VARCHAR)
LANGUAGE SQL
AS $$                                  
   SELECT  CUSTOMER_CODE, CUSTOMERNAME FROM DIM_CUSTOMER
    WHERE  CUSTOMER_CODE ILIKE '%CUSTCODE%'
$$;

或者在里面使用双单..

CREATE OR REPLACE FUNCTION ABC("CUSTCODE" VARCHAR)
RETURNS TABLE ("CUSTOMER_CODE" VARCHAR, CUSTOMERNAME VARCHAR)
LANGUAGE SQL
AS '                                  
   SELECT  CUSTOMER_CODE, CUSTOMERNAME FROM DIM_CUSTOMER
    WHERE  CUSTOMER_CODE ILIKE ''%CUSTCODE%''
';