存储过程例子

create or replace procedure day_street_kh

 is
  yesterday varchar2(30);
  maxTime varchar2(30);
  myCusor SYS_REFCURSOR;

begin
  --参数赋值

  select to_char(sysdate - 1, 'yyyy-MM-dd') into yesterday from dual;
  dbms_output.put_line(yesterday);
 
  select max(t.ymtime) into maxTime from cr_exam_day_stats_bak t ;
   dbms_output.put_line(maxTime);
   
   --插入前删除cr_exam_day_stats 所有数据,
  delete from  cr_exam_day_stats t where  t.typekind='1';
  -- 删除存在的同一天数据
 if(yesterday=maxTime)then
     
    delete from  cr_exam_day_stats_bak t where t.ymtime=yesterday and t.typekind='1';
 
   end if;   

  --游标赋值
  for myCusor in (
    select
       RAWTOHEX(SYS_GUID()) ID,
      '' commname,
        nvl(b.ymtime,yes
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
帮助那些想尽快学习存储过程 实例:create PROCEDURE pagination @tblName varchar(255), -- 表名 @strGetFields varchar(1000) = '*', -- 需要返回的列 @fldName varchar(255)='', -- 排序的字段名 @PageSize int = 10, -- 页尺寸 @PageIndex int = 1, -- 页码 @pagecount int output, -- 返回页总数, 非 0 值则返回 --@OrderType bit = 0, -- 设置排序类型, 非 0 值则降序 @strWhere varchar(1500) = '1=1' -- 查询条件 (注意: 不要加 where) AS declare @sql nvarchar(2000) --获得表中所有记录的条数 declare @recordcount int declare @getcountsql nvarchar(2000) set @getcountsql = N'select @count = count(*) from ' + @tblName + N' where ' + @strWhere exec sp_executesql @getcountsql,N'@count int output',@count=@recordcount output if @recordcount=0 begin set @pagecount = 0 return end declare @lastcount int set @lastcount = @recordcount % @PageSize if @lastcount = 0 set @pagecount = @recordcount / @PageSize else set @pagecount = @recordcount / @PageSize + 1 if @lastcount = 0 or @pageindex < @pagecount begin set @sql = N'select ' + @strGetFields + N' from (select top ' + convert(nvarchar(4),@PageSize) + N' * from (select top ' + convert(varchar(10),@PageSize*@PageIndex) + N' * from ' + @tblName + N' where ' + @strWhere + N' order by ' +@fldName+ N') as t order by ' + @fldName + ' desc) as tt order by ' + @fldName end else begin if @lastcount != 0 and @pageindex = @pagecount begin set @sql = N'select ' + @strGetFields + N' from (select top ' + convert(nvarchar(4),@lastcount) + N' * from (select top ' + convert(varchar(10),@PageSize*@PageIndex) + N' * from ' + @tblName + N' where ' + @strWhere + N' order by ' +@fldName+ N') as t order by ' + @fldName + ' desc) as tt order by ' + @fldName end end print @sql exec sp_executesql @sql go select * from authors declare @pagecount int exec pagination 'authors','*','au_id',5,1, @pagecount output,'state=''CA''' print @pagecount
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值