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

时间:2024-11-02 18:53:35

示例

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
--建表
openGauss=# CREATE SCHEMA hr;
openGauss=# SET CURRENT_SCHEMA = hr;
--创建存储过程dynamic_proc
openGauss=# 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;
/

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

--删除存储过程
openGauss=# DROP PROCEDURE dynamic_proc;

-- 清除当前数据库模式
openGauss=# SET CURRENT_SCHEMA = public;
openGauss=#  DROP SCHEMA hr CASCADE;
support.huaweicloud.com/distributed-devg-v2-gaussdb/gaussdb-12-0525.html