• 存储过程示例


    存储过程示例:

    例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
    )

  • 相关阅读:
    Yii together
    linux 文件处理大杂烩
    Ubuntu 17.10 环境初始化
    关掉 ubuntu bug 报告功能
    git svn 流程
    [Mac] How do I move a window whose title bar is off-screen?
    可爱的Python_课后习题_CDay−5 Python 初体验和原始需求
    python_编程规范
    python_excel
    python_os
  • 原文地址:https://www.cnblogs.com/xunyi/p/8932808.html
Copyright © 2020-2023  润新知