zoukankan      html  css  js  c++  java
  • 隐式游标与程序包

    隐式游标
              sql游标
                     insert
                     delete
                     update
                     select(返回单行记录的查询)
    引用游标类型
              type stucursor is ref cursor;
    程序包和程序包体
              create or replace package pname as
                          procedure p1(b in varchar2);
                          function f1(a in number);
              end pname;

              create or replace package body pbname as
                          procedure p1(b varchar2) as
                          begin
                                  dbms_output.put_line(123);
                          end;
              end pbname;

    隐式游标:

    Declare 
    
    Begin
      /*
      insert
      update
      delete
      select(返回单行的查询)
      */
      Update student s Set s.sbirthday = s.sbirthday + 3650 Where s.class=95031;
      If Sql%Found Then 
        dbms_output.put_line('数据更新成功!');
        --修改的行数
        dbms_output.put_line(Sql%Rowcount);
        Commit;
      Else 
        dbms_output.put_line('更新失败!');
      End If;
    End;

    构建程序包:

    --构建程序包
    Create Or Replace Package stuinfo As
         Type stucur Is Ref Cursor;
         --存储过程
         Procedure showname(scla In Number,stus Out stucur);
         End stuinfo;
         
    --构建程序包体
    Create Or Replace Package Body stuinfo As
         Procedure showname (scla In Number,stus Out stucur)As
           Begin
             Open stus For Select * From student s Where s.class=scla;
           End;
    End stuinfo;

    调用程序包

    --调用程序包存储过程
    Declare 
      i Integer;
      --引用游标
      Type stuc Is Ref Cursor;
      sts stuc;
      stu student%Rowtype;
    Begin
      stuinfo.showname(95033,sts);
      Loop
        Fetch sts Into stu ;
        Exit When sts%Notfound;
        dbms_output.put_line(stu.sname);
      End Loop;
    End;
  • 相关阅读:
    4500 小Q系列故事——屌丝的逆袭
    HDU 1171 Big Event in HDU
    linux库文件 /usr/lib
    HDU 1860 统计字符
    编程之美~~传话游戏
    HDU 1087 Super Jumping! Jumping! Jumping!
    HDU 1203 I NEED A OFFER!
    各种树
    HDU 3127 WHUgirls
    01背包 完全背包 多重背包 二维费用背包
  • 原文地址:https://www.cnblogs.com/jgjk/p/7388900.html
Copyright © 2011-2022 走看看