简体   繁体   English

如何分离从表行中获取的值并将其存储在雪花中的数组中

[英]How to separate a value taken from a table row and store it in an array in a snowflake

I need to return an array in the stored procedure that takes a comma separated string value from a table and divides that string based on the comma and stores them in an array.我需要在存储过程中返回一个数组,该数组从表中获取逗号分隔的字符串值,并根据逗号分割该字符串并将它们存储在一个数组中。

Example: My table has a Column Tab_Val with row value as "COL1,COL2,COL3,COL4" , I need to take this row in my stored procedure and return an array as arr =['COL1','COL2','COL3','COL4']示例:我的表有一个列 Tab_Val,其行值为"COL1,COL2,COL3,COL4" ,我需要在我的存储过程中使用这一行并返回一个数组作为arr =['COL1','COL2','COL3','COL4']

Here is my attempt:这是我的尝试:

CREATE OR REPLACE PROCEDURE TAB()
    RETURNS ARRAY
    LANGUAGE JAVASCRIPT
    AS
    $$
    var arr = [];
    var stmt = snowflake.createStatement({sqlText: "Select Tab_Val From TABLE1"});
    var r = stmt.execute(); 
    return arr;
    $$

Try this尝试这个

CREATE OR REPLACE TABLE ARRAY_TABLE(ARRAY_CONTENT VARCHAR);
INSERT INTO ARRAY_TABLE VALUES('APPLE,ORANGE,GRAPES,PEARS');
SELECT SPLIT(ARRAY_CONTENT, ',') as str_array FROM ARRAY_TABLE;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Snowflake中将表的列名存储在数组中 - How to store the column names of a table in an array in Snowflake 如何在cypress中将值存储在单独的数组或变量中? - How to store value in separate array or variable in cypress? 如何获得选定的 <option>从表并存储到数组中? - How to get the selected value of <option> from table and store into array? 雪花:如何从扁平的日期字符串变量数组中插入表格? - Snowflake: How to insert into a table from a flattened array of date strings variable? 如何在jquery中从表行和列获取所有值到数组 - How to get all value from table row and column to array in jquery 我如何从表的每一行获取值并将其存储在js数组中 - How do i get the values from each row of a table and store them in a js array 从HTML表格删除一行后,如何存储单元格的值? - How can I store the value of a cell upon deleting a row from an HTML table? 如何在不修改数组本身的情况下更改从数组中获取的值? - How can I change a value taken from the array without modifying the array itself? 如何在量角器中存储表格单元格中的值? - How to store value from a table cell in Protractor? SnowFlake 存储过程根据条件从表中删除一行 - SnowFlake stored procedure to delete a row from a table based on a condition
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM