Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >存储过程示例

存储过程示例

作者头像
全栈程序员站长
发布于 2022-09-06 06:20:27
发布于 2022-09-06 06:20:27
9780
举报

大家好,又见面了,我是你们的朋友全栈君。

存储过程示例:

例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

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
加入讨论
的问答专区 >
1产品KOL擅长5个领域
    领券
    问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档