javascript 存储过程- Snowflake -获取所有列和行的详细信息

d7v8vwbk  于 2023-05-05  发布在  Java
关注(0)|答案(1)|浏览(102)

我试图从有10行的表中获取4个列名,我想循环该表中的所有行,并将这些列值作为参数传递到其他存储过程中。
如何存储下面查询的结果集并使用它们来传递for循环?CREATE OR REPLACE PROCEDURE SP_MAIN()RETURNS VARCHAR(16777216)LANGUAGE JAVASCRIPT EXECUTE AS CALLER AS '
var DETS = select * from SNAPSHOT.SNAPSHOT_CONFIG ;snowflake.execute({sqlText:);

;

ryoqjall

ryoqjall1#

我能够做到这一点如下:

CREATE or replace PROCEDURE SNAPSHOPT_SP()
RETURNS VARCHAR
LANGUAGE javascript
AS
$$

//Array created to store parameters. 
var SRC_DATABASE = [];
var SRC_SCHEMA = [];
var TRGT_DATABASE = [];
var SRC_TABLE = [];
var TRGT_TABLE = [];



// create for the following tables
var rs = snowflake.execute( { sqlText: 
` select * from SNAPSHOT.SNAPSHOT_CONFIG `} );

//load values from table into Array,  we will be looping through the array to execute the store proc

while (rs.next()){
    var SRC_DATABASE_NAME = rs.getColumnValue(1);
    SRC_DATABASE.push(SRC_DATABASE_NAME);
    
    var SRC_SCHEMA_NAME = rs.getColumnValue(2);
    SRC_SCHEMA.push(SRC_SCHEMA_NAME);
    
    var TRGT_SCHEMA_NAME = rs.getColumnValue(3);
    TRGT_DATABASE.push(TRGT_SCHEMA_NAME);
    
    var SRC_TABLE_NAME = rs.getColumnValue(4);
    SRC_TABLE.push(SRC_TABLE_NAME);
    
    var TRGT_TABLE_NAME = rs.getColumnValue(5);
    TRGT_TABLE.push(TRGT_TABLE_NAME);
    
                  }
//run store proc for each table name - format for store proc = SP_SNAPSHOT(SRC_DATABASE_NAME, SRC_SCHEMA_NAME, TRGT_SCHEMA_NAME, SRC_TABLE_NAME , TRGT_TABLE_NAME);                  

for (var i = 0; i < SRC_TABLE.length; i++) {
        snowflake.execute( { sqlText: "CALL SP_SNAPSHOT(:1,:2,:3,:4,:5) ;", binds: [SRC_DATABASE[i],SRC_SCHEMA[i],TRGT_DATABASE[i],SRC_TABLE[i],TRGT_TABLE[i]] });
       
        }
$$;

CALL SNAPSHOPT_SP();

相关问题