大家好,又见面了,我是你们的朋友全栈君。
存储过程示例:
例1:创建不带参数的存储过程 输出系统日期 create or replace procedure output_date is begin dbms_output.put_line(sysdate); end output_date;
例2 带参数in和out的存储过程 create or replace procedure get_username(v_id in number, v_username out varchar2) as begin select username into v_username from tab_user where id=v_id; –变量赋值 exception when no_data_found then raise_application_error(-2001,’ID不存在!’); end get_username;
例3:一个高效的数据分页的存储过程、 create procedure pageTest ( @FirstId nvarchar(20)=null, –当前页面里的第一条记录的排序字段的值 @LastID nvarchar(20)=null, –当前页面里的最后一条记录的排序字段的值 @isNext bit=null, –true 1: 下一页; false 0:上一页; @allCount int output, –返回总记录书 @pageSize int output, –返回一夜的记录数 @CurPage int –也好(第几页) 0:第一页;-1最后一页 ) AS if @CurPage = 0 –第一页; begin –统计总记录数 select @allCount=count(ProductId) from Product_test
set @pageSize = 10 –返回第一页的数据 select top 10 ProductId, ProductName, Introduction from Product_test order by ProductId end
else if @CurPage=-1 –表示最后一页
select * from (select top 10 ProductId, ProductName, Introduction
from Product_test order by ProductId desc ) as aa order by ProductId else
begin if @isNext=1 –翻到下一页 select top 10 ProductId, ProductName, Intorduction from Product_test where ProductId > @LastID order by ProductId else –翻到上一页 select * from (select top 10 ProductId, ProductName, Introduction from Product_test where ProductId<@FirstId order by ProductId desc) as ProductId end )
发布者:全栈程序员栈长,转载请注明出处:https://javaforall.cn/155245.html原文链接:https://javaforall.cn
扫码关注腾讯云开发者
领取腾讯云代金券
Copyright © 2013 - 2025 Tencent Cloud. All Rights Reserved. 腾讯云 版权所有
深圳市腾讯计算机系统有限公司 ICP备案/许可证号:粤B2-20090059 深公网安备号 44030502008569
腾讯云计算(北京)有限责任公司 京ICP证150476号 | 京ICP备11018762号 | 京公网安备号11010802020287
Copyright © 2013 - 2025 Tencent Cloud.
All Rights Reserved. 腾讯云 版权所有