0

我正在使用一个过程将行插入到表中。我想返回插入的行数,但我不知道如何从过程中打开变量替换。我已经尝试了以下所有方法,但它们都返回错误:

snowflake.execute({sqlText: '!set variable_substitution=True'});
snowflake.execute({sqlText: 'set variable_substitution=True'});
snowflake.execute({sqlText: '-o variable_substitution=True'});

如何打开此选项以便我可以运行“select &__rowcount;” 让我的数回来?

这是测试程序的代码,如果有帮助的话:

CREATE OR REPLACE PROCEDURE TEST_OF_GETTING_COUNTS()
  RETURNS VARCHAR
  LANGUAGE javascript
  CALLED ON NULL INPUT
  AS
  $$  
    // Turn on variable substitution
    snowflake.execute(
      {sqlText: '!set variable_substitution=True'}
    );
    
    // Prepare SQL to identify tables to be updated
    snowflake.execute({sqlText: 'SELECT 1'});
    
    // Now get the count of rows selected  
    var getCount = snowflake.createStatement({sqlText: "SELECT &__ROWCOUNT;"});
    var rowCountResultSet = getCount.execute();
    while (rowCount.next()) {
      rowCount= rowCountResultSet.getColumnValue(1);
    }

    // Turn off variable substitution
    snowflake.execute({sqlText: '!set variable_substitution=False'});
          
    return rowCount;
  $$;

CALL TEST_OF_GETTING_COUNTS();
4

1 回答 1

0

NickW 在上面的评论中给了我一个指向 Snowflake 文档中的页面的链接,该页面列出了可用于雪花、Statement、ResultSet 和 SfDate 对象的所有 JavaScript 方法。它给了我我需要的东西:getRowCount() 方法。

于 2021-05-07T22:56:43.107 回答