Home  >  Article  >  Database  >  Oracle的函数和存储过程的简单demo

Oracle的函数和存储过程的简单demo

WBOY
WBOYOriginal
2016-06-07 17:27:12925browse

最近的项目中用到了Oracle函数和存储过程,之前一直都是用的sql语句进行数据库操作,这一次用过存储过程之后,发现存储过程确实非

最近的项目中用到了Oracle函数和存储过程,之前一直都是用的sql语句进行数据库操作,,这一次用过存储过程之后,发现存储过程确实非常好用,功能也非常强大所以各写个简单的demo给大家分享:

一、Oracle函数

1.函数的创建
create or replace function SumResult(Param_One in number , Param_Two in number)
return Result number
is
Result number ;
begin
Result := Param_One + Param_two
return Result;
end SumResult;
2.函数的使用
select distinct sumresult(22,44) into sum from tablename;

二、Oracle存储过程

1.存储过程的创建
create or replace procedure PageQuery (
page in number ,
size in number ,
out_list out sysrefcursor)
 is


sql_str varchar(500);
begin
 sql_str := 'select rownum rn,t1.* from info t1 where rownum > ' ||
            (param_page - 1) * param_size || ' and rownum             param_page * param_size;
--输出sql语句 便于检查
dbms_output.put_line(sql_str);
--返回游标
open out_list for sql_str;


end PageQuery;

linux

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn