Snowflake脚本:使用SQL编写存储过程

huangapple go评论67阅读模式
英文:

Snowflake scripting: writing stored procedure using SQL

问题

CREATE OR REPLACE PROCEDURE CITY_INFO(city_name VARCHAR)
RETURNS STRING
LANGUAGE SQL
AS
BEGIN
    -- 验证城市名称
    IF city_name NOT IN ('SYD', 'LDN', 'NYC', 'BER') THEN
        RETURN '无效的城市名称。';
    END IF;

    -- 其余的代码在这里...

END;

我正在使用SQL(Snowflake脚本)在Snowflake中创建存储过程。我希望确保传递的城市名称仅属于这4个城市。然而,这似乎没有起作用。非常感谢任何帮助。

英文:
CREATE OR REPLACE PROCEDURE CITY_INFO(city_name VARCHAR)
RETURNS STRING
LANGUAGE SQL
AS
BEGIN
    -- validate city_name
    IF city_name NOT IN ('SYD', 'LDN', 'NYC', 'BER') THEN
        RETURN 'Invalid CITY NAME.';
    END IF;

 -- The rest of the code goes here...

END;

I'm creating stored procedure in Snowflake using SQL (Snowflake scripting).
I want to ensure that city_name passed only belongs to these 4 cities. However, this doesn't seem to be working. Any help highly appreciated.

答案1

得分: 1

条件必须用 () 括起来:

开始
    -- 验证 city_name
    IF (city_name 不在 ('SYD', 'LDN', 'NYC', 'BER')) THEN
        返回 '无效的城市名称。';
    结束如果;

 -- 其余的代码在这里...

结束;
英文:

The condition must be enclosed with ():

BEGIN
    -- validate city_name
    IF (city_name NOT IN ('SYD', 'LDN', 'NYC', 'BER')) THEN
        RETURN 'Invalid CITY NAME.';
    END IF;

 -- The rest of the code goes here...

END;

huangapple
  • 本文由 发表于 2023年7月7日 04:05:05
  • 转载请务必保留本文链接:https://go.coder-hub.com/76632224.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定