存储过程
2015-10-27 17:04
309 查看
--存储过程
--pl/sql
过程参数有IN/OUT/IN OUT三种类型,其中IN类型可以被过程体引用,但不能改写值;OUT类型不可被过程体引用,但可改写值;IN OUT 既可以被过程体引用,又可以改写值.
在调用in out类型时,调用过程插入参数时,不能直接用常量。必须用变量。这样才能接收out返回来的值。同理:用out的也不能直接用常量。
create procedure div(a int,b int)
as
c float;
begin
c:=a*1.0/b;
dbms_output.put_line(a||'/'||b||'='||c);
Exception
when others then dbms_output.put_line('除数为0');
end;
begin
div(10,0);
end;
begin
div(b=>20,a=>10);
end;
create procedure pc1
(a int:=20,
b int:=30,
c int:=40,
d int:=50)
as
e int;
begin
e:=a+b+c+d;
dbms_output.put_line(e);
end;
begin
pc1(1,2,3,4);
end;
begin
pc1(b=>1,d=>2,c=>3);
end;
begin
pc1(10,d=>2);
end;
create or replace procedure pc2
(a int,b in out int ,c out int )
as
begin
c:=a+b;
b:=a*b;
end;
declare
x int:=20;
y int:=30;
begin
pc2(10, x , y );
dbms_output.put_line(x||','||y);
end;
select * from users
create or replace procedure procAddUser
(
name varchar,
phone varchar,
mail varchar,
loginid varchar,
loginpwd varchar,
gender int:=1,
roleid int:=1,
stateid int:=1,
address varchar:='未知'
)
as
begin
insert into users values (
USERS_ID_ASQ.nextval,name,address,
phone,mail,stateid,0,loginid,loginpwd,
roleid,gender);
end;
begin
procadduser('haha','110','aa@aa.com','haha','123');
end;
select * from users
grant execute on div to abc
grant select on books to abc
create function fndiv
(a int,b int)
return float
as
c float;
begin
c:=a*1.0/b;
return c;
end;
select fndiv(10,20) from dual
select id,title,unitprice, fndiv(unitprice,2) 半价
from books
declare
x float;
begin
x:=fndiv(10,20);
dbms_output.put_line(x);
end;
create or replace package haha1
is
function fndiv(a int,b int) return float;
procedure add(a int,b int);
end;
create or replace package body haha1
is
function fndiv(a int,b int) return float
as
begin
return a*1.0/b;
end;
procedure add(a int,b int)
as
c int;
begin
c:=a+b;
dbms_output.put_line(c);
end;
end;
select haha1.fndiv(10,20) from dual
begin
haha1.add(10,haha1.fndiv(10,20));
end;
--pl/sql
过程参数有IN/OUT/IN OUT三种类型,其中IN类型可以被过程体引用,但不能改写值;OUT类型不可被过程体引用,但可改写值;IN OUT 既可以被过程体引用,又可以改写值.
在调用in out类型时,调用过程插入参数时,不能直接用常量。必须用变量。这样才能接收out返回来的值。同理:用out的也不能直接用常量。
create procedure div(a int,b int)
as
c float;
begin
c:=a*1.0/b;
dbms_output.put_line(a||'/'||b||'='||c);
Exception
when others then dbms_output.put_line('除数为0');
end;
begin
div(10,0);
end;
begin
div(b=>20,a=>10);
end;
create procedure pc1
(a int:=20,
b int:=30,
c int:=40,
d int:=50)
as
e int;
begin
e:=a+b+c+d;
dbms_output.put_line(e);
end;
begin
pc1(1,2,3,4);
end;
begin
pc1(b=>1,d=>2,c=>3);
end;
begin
pc1(10,d=>2);
end;
create or replace procedure pc2
(a int,b in out int ,c out int )
as
begin
c:=a+b;
b:=a*b;
end;
declare
x int:=20;
y int:=30;
begin
pc2(10, x , y );
dbms_output.put_line(x||','||y);
end;
select * from users
create or replace procedure procAddUser
(
name varchar,
phone varchar,
mail varchar,
loginid varchar,
loginpwd varchar,
gender int:=1,
roleid int:=1,
stateid int:=1,
address varchar:='未知'
)
as
begin
insert into users values (
USERS_ID_ASQ.nextval,name,address,
phone,mail,stateid,0,loginid,loginpwd,
roleid,gender);
end;
begin
procadduser('haha','110','aa@aa.com','haha','123');
end;
select * from users
grant execute on div to abc
grant select on books to abc
create function fndiv
(a int,b int)
return float
as
c float;
begin
c:=a*1.0/b;
return c;
end;
select fndiv(10,20) from dual
select id,title,unitprice, fndiv(unitprice,2) 半价
from books
declare
x float;
begin
x:=fndiv(10,20);
dbms_output.put_line(x);
end;
create or replace package haha1
is
function fndiv(a int,b int) return float;
procedure add(a int,b int);
end;
create or replace package body haha1
is
function fndiv(a int,b int) return float
as
begin
return a*1.0/b;
end;
procedure add(a int,b int)
as
c int;
begin
c:=a+b;
dbms_output.put_line(c);
end;
end;
select haha1.fndiv(10,20) from dual
begin
haha1.add(10,haha1.fndiv(10,20));
end;
相关文章推荐
- c++ switch case
- 4000 堆排序(C#)
- 第九周 项目2 对称矩阵压缩存储的实现与应用
- 003.main 主函数文件
- 编写测量矩阵代码需要用到的几个常见函数
- 网页中植入媒体播放器
- 004androidStudio ndk开发环境
- 10.27
- Oracle批量导出AWR报告
- iOS—dictionary写入文件出现的几个问题
- 数组指针与指针数组
- 谈外包项目
- 第9周—项目3(2)两个稀疏矩阵相加的运算
- 基因检测-外显子链接问题
- 004.self 用来调用方法
- MyBatis学习总结(一)——MyBatis快速入门
- 设置tabbaritem的title的颜色及按钮图片
- SpringMVC与LogBack集成
- JS中的prototype
- UVa 10815 - Andy's First Dictionary【排序+去重】