从 table 中在雪花中设置多个变量的最佳方法是什么
What is the best way to set multiple variables in snowflake from a table
等效声明和设置变量如下。
DECLARE @name varchar(255)
,@address varchar(255)
,@country varchar(255)
SELECT @name = name
,@address = address
,@country = country
FROM tbl_address
WHERE id =5
将此代码转换为雪花 SP 时,处理声明和设置变量的最佳方法是什么 table。
可以一次赋值多个变量:
CREATE OR REPLACE TABLE tbl_address AS
SELECT 5 AS id, 'a' AS name, 'b' AS address, 'c' AS country;
SET (name, address, country) = (SELECT name, address, country
FROM tbl_address WHERE id = 5);
SELECT $name, $address, $country;
-- a, b, c
要求是用于取值的子查询不能return超过1行。
等效声明和设置变量如下。
DECLARE @name varchar(255)
,@address varchar(255)
,@country varchar(255)
SELECT @name = name
,@address = address
,@country = country
FROM tbl_address
WHERE id =5
将此代码转换为雪花 SP 时,处理声明和设置变量的最佳方法是什么 table。
可以一次赋值多个变量:
CREATE OR REPLACE TABLE tbl_address AS
SELECT 5 AS id, 'a' AS name, 'b' AS address, 'c' AS country;
SET (name, address, country) = (SELECT name, address, country
FROM tbl_address WHERE id = 5);
SELECT $name, $address, $country;
-- a, b, c
要求是用于取值的子查询不能return超过1行。