首页 > 数据库技术 > 详细

PLSQL 申明和游标

时间:2016-12-09 19:26:05      阅读:212      评论:0      收藏:0      [点我收藏+]
--从键盘输入一个数
accept b prompt 请输入一个大于零的数字;
declare
 anum number := &b;
begin
  while anum>0
    loop
      dbms_output.put_line(anum);
      anum:=anum-1;
    end loop;
end;




declare
    v_num number;
begin
-- 从stsu表中选出id最大的值,并根据该值打印次数
  select max(id) into v_num from stsu;
  loop
  dbms_output.put_line(v_num);
  v_num := v_num-1;
  exit when v_num=0;
  end loop;
end;




declare
    cursor cur is select id,math from stsu;
begin
    for cur in (select id,math from stsu)
      loop
        dbms_output.put_line(cur.id ||编号学员的数学分数:||cur.math);
      end loop;
end;



declare 
  cursor cursor_id is select id,math from stsu;
  v_id stsu.id%type;
  v_math stsu.math%type;
begin 
  --打开游标
  open cursor_id;
  loop 
    -- 抓取数据
    fetch cursor_id into v_id,v_math;
    exit when cursor_id%notfound;
    dbms_output.put_line(v_id||  ||v_math);
    end loop;
    -- 关闭游标
    close cursor_id;
end;

 

PLSQL 申明和游标

原文:http://www.cnblogs.com/lantu1989/p/6150384.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!