plsql learning - three:debug

本文介绍了一个使用PLSQL Developer进行调试的方法,并通过一个批量处理学生数据的包实现示例,展示了如何打开和关闭游标、批量获取数据以及打印数据。

The debug method three: we can use the debug tools of plsql developer,just like we debug our code in eclipse or vc.

  

create or replace package StudentFetch as
  type t_Students is table of students%rowtype
  index by binary_integer;
  
  --open the cursor for processing
  procedure OpenCursor;
  
  --close the cursor
  procedure CloseCursor;
  
  --return up to p_BatchSize rows in p_Students
  function FetchRows(p_BatchSize in out number,p_Students out t_students)
  return boolean;
  
  --print the p_BatchSize rows from p_Students
  procedure PrintRows(p_BatchSize in number,p_Students in t_students);
  
  end StudentFetch;

create or replace package body StudentFetch as
cursor c_AllStudents is
  select * from students order by id;
  
  --open the cursor for processing
  procedure OpenCursor is
  begin 
      open c_AllStudents;
  end  OpenCursor;
  --close the cursor
  procedure CloseCursor is
    begin
      close c_AllStudents;
    end CloseCursor;
    
  --return up to p_BatchSize rows in p_Students
  function FetchRows(p_BatchSize in out number,p_Students out t_students)
  return boolean is
  v_Finished boolean := true;
  begin 
    for v_Count in 1..p_BatchSize loop
      fetch c_AllStudents into p_Students(v_Count);
        if c_AllStudents%notfound then
          v_Finished := false;
          p_BatchSize := v_Count - 1;
          exit;
        end if;
     end loop;
     return v_Finished;
   end FetchRows;
   
  --print the p_BatchSize rows from p_Students
  procedure PrintRows(p_BatchSize in number,p_Students in t_students) is
  begin 
    for v_Count in 1..p_BatchSize loop
      dbms_output.put('ID: '||p_Students(v_Count).ID);
      dbms_output.put('Name: '||p_Students(v_Count).first_name);
      dbms_output.put_line(' '||p_Students(v_Count).last_name);
    end loop;
  end PrintRows;
 end StudentFetch;
  
  --test procedure
  create or replace procedure TestCredit is
  v_BatchSize number:=5;
  v_Students StudentFetch.t_Students;
  begin
    StudentFetch.OpenCursor;
    while StudentFetch.FetchRows(v_BatchSize,v_Students) loop
      StudentFetch.PrintRows(v_BatchSize,v_Students);
    end loop;
    if v_BatchSize != 0 then
      StudentFetch.PrintRows(v_BatchSize,v_Students);
    end if;
    StudentFetch.CloseCursor;
  end TestCredit;

we can set breakpoint of the procedure,then go to find the value of every step we executed.it is convenient.

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值