从存储过程中进行选择
Some stored procedures return tabular data. To select and manipulate this tabular data, you can call these stored procedures in the FROM clause of a SELECT statement.
运行具有 TABLE 关键字的 SELECT 语句¶
When calling the stored procedure, omit the CALL command. Instead, use the TABLE keyword, and name the procedure inside parentheses:
从存储过程中进行选择的示例
此示例使用下表中的数据:
以下存储过程会返回基于用户 ID 的订单信息:
Note: If you use Snowflake CLI, SnowSQL, the Classic Console, or the
execute_stream or execute_string method in Python Connector
code, use this example instead (see Using Snowflake Scripting in Snowflake CLI, SnowSQL, and Python Connector):
以下 SELECT 语句将检索存储过程的结果:
从存储过程中进行选择的限制
以下限制适用于从存储过程中进行选择:
-
Only stored procedures that perform SELECT, SHOW, DESCRIBE, or CALL statements can be placed in the FROM clause of a SELECT statement. Stored procedures that make modifications using DDL or DML operations aren’t allowed. For stored procedures that issue CALL statements, these limitations apply to the stored procedures that are called.
-
Only stored procedures that return tabular data with a static output schema can be placed in the FROM clause of a SELECT statement. The output columns must be named and typed. For example, a stored procedure with the following RETURNS clause is supported:
不支持具有以下 RETURNS 子句的存储过程,因为它不返回表格数据:
不支持具有以下 RETURNS 子句的存储过程,因为它不提供固定的输出架构:
-
必须使用以下语句之一的 SELECT 块的 FROM 子句调用存储过程:
-
The stored procedure can’t accept correlated input arguments from their outer scope, such as a reference to any CTE defined outside of the SELECT statement.
-
如果实参包含子查询,则该子查询不能使用 WITH 子句定义的 CTE。
-
A SELECT statement containing a stored procedure call can’t be used in the body of a view, a user-defined function (UDF), a user-defined table function (UDTF), or in objects such as row access policies and data masking policies.
-
You can’t use bind variables in a SELECT statement that calls a stored procedure. For example, the following SELECT statements aren’t allowed: