[英]Numeric value '"+i+"' is not recognized At Statement.execute in snowflake stored procedure while executing below code?
Below is the stored procedure which uses for loop using java script下面是使用 java 脚本进行循环的存储过程
create or replace procedure test()
returns varchar
language javascript
execute as caller
as
$$
for (var i = 1; i<= 10; i++)
{
var command8=` update table a set a.c1='some' from table b where a.source='gg' and b.c2=a.c2 and b.c3=a.c3 and (datediff(year,date(a.etl_create),current_date())= '"+i+"')`
var stmt8=snowflake.createStatement({sqlText: command8});
var rs8=stmt8.execute();
}
To substitute a variable into a template literal, use ${variable}
.要将变量替换为模板文字,请使用
${variable}
。
var command8=` update table a set a.c1='some' from table b where a.source='gg' and b.c2=a.c2 and b.c3=a.c3 and (datediff(year,date(a.etl_create),current_date())= '${i}')`
Using bidning variables :使用出价变量:
for (var i = 1; i<= 10; i++)
{
var command8=` update table a set a.c1='some'
from table b
where a.source='gg' and b.c2=a.c2 and b.c3=a.c3
and (datediff(year,date(a.etl_create),current_date())= :1)`
var stmt8=snowflake.createStatement({sqlText: command8, binds:[i]});
var rs8=stmt8.execute();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.