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;

/

調用包的過程

SCOTT@VDEDU > 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.

SCOTT@VDEDU > set serveroutput on

SCOTT@VDEDU > /

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;

/


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM