Oracle存储过程模板

// Procedure版

Create Or Replace Procedure Abc( n Number) Is --输入参数
    Type Cursortype Is Ref Cursor;                                                       --定义游标类型,好的使用方式
    Resultset Cursortype;                                       --定义游标变量
    Deptstate Tb000000department%Rowtype;                       --定义行对象
    Strsql Varchar2(500) := 'create or replace view aView as('; --变量初始化
  Begin
    Open Resultset For --打开游标
    --查询所有座席在某小时内的各状态的汇总时间
    Select * From Tb000000department t;
    Loop --循环遍历游标
      Fetch Resultset Into Deptstate;
      Exit  When Resultset%Notfound;
      If n > 0 Then
        Dbms_Output.Put_Line(Strsql || '+' || Deptstate.Lid || '+' || n);
      End If;
    End Loop;
    --关闭游标
    Close Resultset;
  Exception
    WHEN myException THEN   
        Dbms_Output.Put_Line('have an error!');
    When Others Then
      Begin
        If Resultset%Isopen Then
          Close Resultset;
        End If;
      End;
  End Abc;

 

PL/SQL块版:

DECLARE
    Type Cursortype Is Ref Cursor;
    Resultset Cursortype;
    Deptstate employee%Rowtype;
    Strsql Varchar2(500) := 'hello world!';
    lId    Number        :=100;
    myException EXCEPTION;
  Begin
    Open Resultset For Select * From employee t;
    Loop
      Fetch Resultset Into Deptstate;
      Exit When Resultset%Notfound;
      If Deptstate.Lid > 50 Then
        Dbms_Output.Put_Line(Strsql || '+' || Deptstate.Lid || '+' || lId);
      End If;
    End Loop;
    Close Resultset;
  Exception
    WHEN myException THEN  
      Dbms_Output.Put_Line('have an error!');
    When Others Then
    Begin
      If Resultset%Isopen Then
        Close Resultset;
      End If;
    End;
End;
/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值