[英]SnowFlake: Access rights in SQL vs. procedures
I have the following initial situation in SnowFlake: I want to retrieve the NextVal of a sequence in a procedure and get the following error message when calling the procedure:我在 SnowFlake 中有以下初始情况:我想在过程中检索序列的 NextVal 并在调用该过程时收到以下错误消息:
Uncaught exception of type 'STATEMENT_ERROR' on line 3 at position 29: SQL compilation error: error line 1 at position 7 invalid identifier 'COMMON.SEQ_LAUF_ID'.
在 position 29 处的第 3 行未捕获类型为“STATEMENT_ERROR”的异常:SQL 编译错误:在 position 7 处的错误行 1 无效标识符“COMMON.SEQ_LAUF_ID”。
A select with the same user/role works fine:具有相同用户/角色的 select 工作正常:
Example SQL:示例 SQL:
SELECT COMMON.SEQ_LAUF_ID as nv FROM DUAL ;
Example Proc:示例过程:
create or replace procedure MDP_Codes ( )
returns varchar
language sql
EXECUTE AS CALLER
as
$$
DECLARE
rs resultset default ( SELECT COMMON.SEQ_LAUF_ID as nv FROM DUAL ) ;
hCur cursor for rs ;
SQL_lauf_id varchar ;
BEGIN
for hRow in hCur do
SQL_lauf_id := hRow.nv ;
end for;
return SQL_lauf_id ;
END;
$$
;
call APPSMITH.MDP_Codes();
The code SELECT COMMON.SEQ_LAUF_ID as nv FROM DUAL;
代码
SELECT COMMON.SEQ_LAUF_ID as nv FROM DUAL;
is incorrect as it lacks NEXTVAL
不正确,因为它缺少
NEXTVAL
SELECT COMMON.SEQ_LAUF_ID as nv FROM DUAL ;
-- Invalid reference to sequence object without nextval: COMMON.SEQ_LAUF_ID.
-- should be
SELECT COMMON.SEQ_LAUF_ID.NEXTVAL as nv FROM DUAL ;
To grab the next value from sequence there is no need to use RESULTSET
and cursor loop, simple assignment will suffice.要从序列中获取下一个值,无需使用
RESULTSET
和 cursor 循环,简单的赋值就足够了。
Full demo:完整演示:
CREATE SCHEMA COMMON;
CREATE SEQUENCE COMMON.SEQ_LAUF_ID;
SELECT COMMON.SEQ_LAUF_ID.NEXTVAL;
-- 1
create or replace procedure MDP_Codes ( )
returns varchar
language sql
EXECUTE AS CALLER
as
$$
DECLARE
SQL_lauf_id VARCHAR;
BEGIN
SQL_lauf_id := (SELECT COMMON.SEQ_LAUF_ID.NEXTVAL);
return SQL_lauf_id ;
END;
$$
;
CALL MDP_Codes();
-- MDP_CODES
-- 2
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.