oracle包(package)的使用

1,创建包头:
create or replace package testpackage is
  -- Public type declarations
  procedure test1(name in varchar2,outname out varchar2);
  procedure test2(name in varchar2,outname out varchar2);
  procedure test3(name in varchar2,outname out varchar2);
 
end testpackage;
 
2,创建包体:
create or replace package body testpackage is
 
  -- Private type declarations
  procedure test1(name in varchar2,outname out varchar2) as 
    vs_tmpstr varchar(100);
    begin
      vs_tmpstr := '来自test1';
      outname := vs_tmpstr||' '||name;
    end test1;
  procedure test2(name in varchar2,outname out varchar2) as 
    vs_tmpstr varchar(100);
    begin
      vs_tmpstr := '来自test2';
      outname := vs_tmpstr||' '||name;
    end test2; 
  procedure test3(name in varchar2,outname out varchar2) as 
    vs_tmpstr3 varchar(100);
    begin
      test1(name,vs_tmpstr3);
      outname := vs_tmpstr3;
    end test3;     
end testpackage;
 
3,创建testpackage_two包可以调用testpackage包:
create or replace package body testpackage_two is
 
  procedure test1(name in varchar2) as 
    vs_tmpstr varchar(100);
    begin
      -- 调用其他包
      testpackage.test1(name,vs_tmpstr);
      dbms_output.put_line(vs_tmpstr);
    end test1;
end testpackage_two;
 
4,运行testpackage包:
declare vs_outstr varchar(100);
begin
  testpackage.test3('0001',vs_outstr);
  dbms_output.put_line(vs_outstr);
end;
 
5,运行testpackage_two包:
call testpackage_two.test1('0012')

爆款云服务器s6 2核4G 低至0.46/天,具体规则查看活动详情Blog Img