云数据库 GAUSSDB-动态调用匿名块:示例

时间:2024-01-23 20:09:24

示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
--创建存储过程dynamic_proc
postgres=# CREATE OR REPLACE PROCEDURE dynamic_proc
AS
   staff_id     NUMBER(6) := 200;
   first_name   VARCHAR2(20);
   salary       NUMBER(8,2);
BEGIN
    --执行匿名块 
    EXECUTE IMMEDIATE 'begin select first_name, salary into :first_name, :salary from hr.staffs where staff_id= :dno; end;'
       USING OUT first_name, OUT salary, IN staff_id;
   dbe_output.print_line(first_name|| ' ' || salary);
END;
/

--调用存储过程
postgres=# CALL dynamic_proc();

--删除存储过程
postgres=# DROP PROCEDURE dynamic_proc;
support.huaweicloud.com/devg-v1-gaussdb/gaussdb_devg_0673.html