在 Snowflake 存储过程的 If-Else 块中使用 LIKE 运算符所需的指导
Guidance needed with using LIKE operator in If-Else block of a Snowflake Stored procedure
我正在尝试创建类似于以下代码的 Snowflake 存储过程。但是 if-else 块中的 like 运算符不起作用。
存储过程
create or replace procedure test_stored_procedure(inputvalue varchar)
returns string not null
language javascript
as
$$
if (inputvalue like '%abc%') { return 'valid input' } else { return 'invalid input'}
$$
;
调用程序时出现以下错误
JavaScript compilation error: Uncaught SyntaxError: Unexpected identifier in test_stored_procedure at ' if (inputvalue like '%abc%') { return 'valid input' } else { return 'invalid input'}' position 14
JavaScript 等价于 LIKE '%abc%'
是 includes('abc')
:
create or replace procedure test_stored_procedure(inputvalue VARCHAR)
returns string not null
language javascript
as
$$
if ( INPUTVALUE.includes('abc')) {
return 'valid input';
}
else {
return 'invalid input';
}
$$;
测试:
CALL TEST_STORED_PROCEDURE('fabc');
-- valid input
CALL TEST_STORED_PROCEDURE('xyz');
-- invalid input
备注:
语句应以 ;
和 结束
JavaScript 参数中区分大小写:
For stored procedures (and UDFs) that use JavaScript, identifiers (such as argument names) in the SQL portion of the statement are converted to uppercase automatically (unless you delimit the identifier with double quotes), while argument names in the JavaScript portion will be left in their original case
我正在尝试创建类似于以下代码的 Snowflake 存储过程。但是 if-else 块中的 like 运算符不起作用。
存储过程
create or replace procedure test_stored_procedure(inputvalue varchar)
returns string not null
language javascript
as
$$
if (inputvalue like '%abc%') { return 'valid input' } else { return 'invalid input'}
$$
;
调用程序时出现以下错误
JavaScript compilation error: Uncaught SyntaxError: Unexpected identifier in test_stored_procedure at ' if (inputvalue like '%abc%') { return 'valid input' } else { return 'invalid input'}' position 14
JavaScript 等价于 LIKE '%abc%'
是 includes('abc')
:
create or replace procedure test_stored_procedure(inputvalue VARCHAR)
returns string not null
language javascript
as
$$
if ( INPUTVALUE.includes('abc')) {
return 'valid input';
}
else {
return 'invalid input';
}
$$;
测试:
CALL TEST_STORED_PROCEDURE('fabc');
-- valid input
CALL TEST_STORED_PROCEDURE('xyz');
-- invalid input
备注:
语句应以 ;
和 结束
JavaScript 参数中区分大小写:
For stored procedures (and UDFs) that use JavaScript, identifiers (such as argument names) in the SQL portion of the statement are converted to uppercase automatically (unless you delimit the identifier with double quotes), while argument names in the JavaScript portion will be left in their original case