一、存储过程
一般存储过程的结构:
create or replace procedure 过程名(参数 数据类型)as/is
声明变量
begin
过程;
异常处理;
end;
例:
创造一个简单整数的加法器
create or replace procedure pro_add (a in out int,b in int) as
begin
a :=a+b;
print a;
exception
when others then null;
end;
调用
call pro_add (10,11);
结果:
21
二、存储函数
一般存储函数的结构
create or replace function 函数名(参数 数据类型) return 数据类型 as/is
变量名 数据类型
begin
函数内容;
异常处理;
end;
例:
创建一个整数加法函数
create or replace function fun_add (a int,b int) return int as
s int;
begin
s :=a+b;
return s;
exception
when others then null;
end;
调用
select fun_add (10,11);
三、总结
1.存储过程没有返回值,只能通过参数in out来得到执行结果;
2.存储过程没有返回语句,存储函数必须以返回语句结尾return;
3.不能在存储过程的返回语句中带表达式,而存储函数必须带表达式;
4.存储过程不能出现在一个表达式中,而存储函数可以出现在表达式中。