云数据库 GaussDB-CREATE PACKAGE:示例

时间:2023-11-01 16:22:10

示例

  • CREATE PACKAGE SPECIFICATION示例
    CREATE OR REPLACE PACKAGE emp_bonus ISvar1 int:=1;--公有变量var2 int:=2;PROCEDURE testpro1(var3 int);--公有存储过程,可以被外部调用END emp_bonus;/
  • CREATE PACKAGE BODY示例
    drop table if exists test1;create or replace package body emp_bonus isvar3 int:=3;var4 int:=4;procedure testpro1(var3 int)isbegincreate table if not exists test1(col1 int);insert into test1 values(var1);insert into test1 values(var4);end;begin  --实例化开始var4:=9;testpro1(var4);end emp_bonus;/
  • ALTER PACKAGE OWNER示例
    ALTER PACKAGE emp_bonus OWNER TO omm;--将PACKAGE emp_bonus的所属者改为omm
  • 调用PACKAGE示例
    call emp_bonus.testpro1(1); --使用call调用package存储过程select emp_bonus.testpro1(1); --使用select调用package存储过程--匿名块里调用package存储过程beginemp_bonus.testpro1(1);end;/
support.huaweicloud.com/centralized-devg-v2-opengauss/devg_03_0560.html