创建包(package)
函数:
create or replace package 包名 as 函数
注意:as后可加多个函数
存储过程:
Create or replace package 包名 as 存储过程
注意:as后可加多个存储过程
函数的包调用:
call 包名.函数名;
存储过程的包调用:
call 包名.存储过程名;
无参数存储过程
create procedure stu_proc1 as p_name varchar2(32);
begin
select sname into p_name from stu where sno='001';
dbms_output.put_line(p_name);
end;
call stu_proc1(); --调用方法一
带有输入参数的存储过程
仅仅带有输入参数的存储过程
实例1
create procedure stu_proc2(pno in stu.sno%type) as
pname varchar2(30);
begin
select sname into pname from stu where sno=pno;
dbms_output.put_line(pname);
end;
实例2
create or replace function get_stu2(pno in stu.sno%type) return varchar2 as
pname varchar2(30);
begin
stu_proc2(pno);
select sname into pname from stu where sno=pno;
return pname;
end;
--调用
declare
begin
dbms_output.put_line('打印的结果是:'||get_stu2(2));
end;
带输出参数的存储过程
实例1
create or replace procedure stu_proc3(pname out stu.sname%type)as
begin
select sname into pname from stu where sno=2;
dbms_output.put_line(pname);
end;
实例2
create or replace function get_stu3(pname out varchar2) return varchar2 is
begin
stu_proc3(pname );
return pname;
end;
--调用
declare
pname stu.sname%type;
begin
dbms_output.put_line('打印的结果是:'||get_stu3(pname));
end;
实例3
create or replace function get_stu2(pno in stu.sno%type) return varchar2 as
pname varchar2(30);
begin
stu_proc2(pno);
select sname into pname from stu where sno=pno;
return pname;
end;
--调用
declare
begin
dbms_output.put_line('打印的结果是:'||get_stu2(2));
end;