标签:little output let ack creat put body bsp sel
创建包头
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;
/
标签:little output let ack creat put body bsp sel
原文地址:https://www.cnblogs.com/kawashibara/p/9047456.html