开发者问题收集

100132 (P0000):JavaScript 执行错误:未捕获的 ReferenceError:

2020-02-03
5282

我正在练习使用 try 和 catch 进行存储过程的用例,获取错误 num is not defined。但获取以下完整错误。

100132 (P0000): JavaScript execution error: Uncaught ReferenceError: num is not defined in SP at '    var sql_comm = "insert into test_sp (col) values(" + num + ")";' position 57

stackstrace: SP 行:2

以下是我的代码

    create or replace TABLE TEST_SP (
       COL NUMBER(38,0)                                                                       
 );

create or replace procedure sp ( num float )
    returns float
    language javascript
    strict
    execute as owner
    as
    $$
    var sql_comm = "insert into test_sp values(" + num + ")";
    try {
            snowflake.execute(
                    {sqlText:sql_comm}
                );
            return "succeeded"
    }
    catch (err){
        return "failed" + err ;
    }
    $$
    ;

    call sp(2::float);
2个回答

存储过程内的参数 NUM 需要全部大写。并且您返回 float ,但在修复之后返回字符串/ text ,因此在我的示例中,我将其更改为返回 TEXT ,但我怀疑这只是您测试的功能。

create or replace procedure sp ( num float )
returns text
language javascript
strict
execute as owner
as
$$
var sql_comm = "insert into test_sp values(" + NUM + ")";
try {
        snowflake.execute(
                {sqlText:sql_comm}
            );
        return "succeeded"
}
catch (err){
    return "failed" + err ;
}
$$
;

有效:

调用 sp(2::float);

给出:

SP
succeeded

并检查:

select * from test_sp;

给出:

COL
2
2
2
Simeon Pilgrim
2020-02-03

存储过程内的所有参数都应该大写,将参数改为大写即可解决问题。

Sriga
2020-02-05