PLSQL Package包的使用

Posted 张欣橙

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了PLSQL Package包的使用相关的知识,希望对你有一定的参考价值。

创建包头

create or replace package pak_kingsql is

procedure pro_kingsql(p_one in varchar2,p_two out varchar2,p_three in out varchar2);

function f_nianxin(v_sal in emp.sal%type)return number;

end;

/

创建包体

create or replace package body pak_kingsql is

procedure pro_kingsql(p_one in varchar2,p_two out varchar2,p_three in out varchar2)

is

begin

dbms_output.put_line(‘parameter: ‘||‘p_one: ‘||p_one||‘,p_two: ‘||p_two||‘,p_three:‘||p_three);

end pro_kingsql;

function f_nianxin

(v_sal in emp.sal%type)

return number

is

v_sal2 emp.sal%type:=0;

begin

v_sal2:=v_sal*12;

return v_sal2;

end f_nianxin;

end pak_kingsql;

/

调用包的过程

[email protected] > declare

  2  TWO varchar2(20):=‘hehe‘;

  3  THREE varchar2(20):=‘haha‘;

  4  begin

  5  pak_kingsql.pro_kingsql(‘kingsql‘,TWO,THREE);

  6  end;

  7  /

PL/SQL procedure successfully completed.

[email protected] > set serveroutput on

[email protected] > /

parameter: p_one: kingsql,p_two: ,p_three:haha

PL/SQL procedure successfully completed.

调用包的函数

select pak_kingsql.f_nianxin(sal) from emp;

PAK_KINGSQL.F_NIANXIN(SAL)

--------------------------

      9600

     19200

     15000

     35700

     15000

     34200

     29400

     36000

     60000

     18000

     13200

PAK_KINGSQL.F_NIANXIN(SAL)

--------------------------

     11400

     36000

     15600

删除包

DROP PACKAGE package_name;

DROP PACKAGE BODY package_name;

创建一个包 把之前的工资等级过程和函数放进去

包头

create or replace package pak_sal is

procedure pro_emp_02(v_eno emp.empno%type);

function f_grade(v_eno in emp.empno%type)

return varchar2;

end;

/

包体

create or replace package body pak_sal is

procedure pro_emp_02(v_eno emp.empno%type)

is

v_ename emp.ename%type;

v_sal emp.sal%type;

begin

select ename,sal into v_ename,v_sal from emp where empno=v_eno;

case

when v_sal between 0 and 2000 then

dbms_output.put_line(v_ename||‘‘‘s salary is‘||v_sal||‘little case‘);

when v_sal between 2001 and 5000 then

dbms_output.put_line(v_ename||‘‘‘s salary is‘||v_sal||‘medium case‘);

when v_sal>5000 then

dbms_output.put_line(v_ename||‘‘‘s salary is‘||v_sal||‘funny‘);

else

dbms_output.put_line(v_ename||‘‘‘s salary is‘||v_sal||‘not funny‘);

end case;

end pro_emp_02;

function f_grade(v_eno in emp.empno%type)

return varchar2

is

v_sal emp.sal%type;

v_result varchar2(50);

begin

select sal into v_sal from emp where empno=v_eno;

case

when v_sal>1 and v_sal<2000 then

v_result:=‘little case‘;

when v_sal>2000 and v_sal<5000 then

v_result:=‘medium case‘;

when v_sal>5000 then

v_result:=‘big case‘;

else

v_result:=‘no case‘;

end case;

return v_result;

end f_grade;

end pak_sal;

/

以上是关于PLSQL Package包的使用的主要内容,如果未能解决你的问题,请参考以下文章

Java——包的概念及使用

Plsql developer 工具创建存储过程,必须要在package 文件下创建存储声明 pa

npm package.js Guide

package.json与package-lock.json的区别

plsql安装

包的定义和导入,系统常用的包