--创建存储过程
create or replace procedure pro_emp
is
esal number;
begin
select avg(sal) into esal from emp;
dbms_output.put_line(esal);
end pro_emp;
--创建函数
create or replace function fun_emp(mysal number)
return varchar2
is
esal number;
begin
select avg(sal) into esal from emp;
if esal>=mysal then
return '薪水高于平均工资';
else
return '薪水低于平均工资';
end if;
end fun_emp;
--创建程序包规范
create or replace package pack_demo
is
procedure pro_emp;--过程的声明部分
function fun_emp(mysal number) return varchar2;--函数的声明部分
end pack_demo;
--创建程序包主体
create or replace package body pack_demo
is
procedure pro_emp
is
esal number;
begin
select avg(sal) into esal from emp;
dbms_output.put_line(esal);
end pro_emp;
function fun_emp(mysal number)
return varchar2
is
esal number;
begin
select avg(sal) into esal from emp;
if esal>=mysal then
return '薪水高于平均工资';
else
return '薪水低于平均工资';
end if;
end fun_emp;
end pack_demo;
execute pack_demo.pro_emp;--执行存储过程
select pack_Demo.fun_emp from dual;--操作函数