CASE (Snowflake Scripting)¶
CASE 语句提供一种指定多个条件的方法。
有关分支结构的更多信息,请参阅 使用条件逻辑。
备注
本 Snowflake Scripting 结构仅在 Snowflake Scripting 区块 内有效。
语法¶
简单 CASE 语句:
其中:
搜索的 CASE 语句:
其中:
使用说明¶
如果
CASE的多个分支与表达式匹配,则只使用第一个分支。比较表达式时, NULL 与 NULL 不匹配。如果要显式测试 NULL 值,请使用 IS [ NOT ] NULL。
示例¶
此示例演示了一个简单的 CASE 语句:
Note: If you use Snowflake CLI, SnowSQL, the Classic Console, or the
execute_streamorexecute_stringmethod in Python Connector code, use this example instead (see Using Snowflake Scripting in Snowflake CLI, SnowSQL, and Python Connector):
调用此存储过程时,该过程将生成以下输出:
此示例演示搜索的 CASE 语句:
Note: If you use Snowflake CLI, SnowSQL, the Classic Console, or the
execute_streamorexecute_stringmethod in Python Connector code, use this example instead (see Using Snowflake Scripting in Snowflake CLI, SnowSQL, and Python Connector):
调用此存储过程时,该过程将生成以下输出: