sql有关循环

declare
  str         varchar2(200);
  nowTime     Date;
  a           number(10);
  b           number(10);
  start_value number;
  end_value   number;
begin
  select sysdate into nowTime from dual;
  str := '  分隔符 ';
  -- CHR(10)||CHR(13)||
  DBMS_OUTPUT.PUT_LINE('------------当前时间--------------' || str /*|| CHR(10)*/
                       || CHR(13) ||
                       to_char(nowTime, 'YYYY-MM-DD hh24:mi:ss'));
  a := 100;
  b := 200;
  if a < b then
    DBMS_OUTPUT.PUT_LINE('-------a<b-------');
  end if;
  -- while 循环
  DBMS_OUTPUT.PUT_LINE('------------while 循环--------------');
  start_value := 1;
  end_value   := 10;
  while start_value <= end_value loop
    DBMS_OUTPUT.PUT_LINE('now number:' || start_value);
    start_value := start_value + 1;
  end loop;
  -- for循环
  DBMS_OUTPUT.PUT_LINE('------------for循环--------------');
  for tmp in 10 .. 20 loop
    if mod(tmp, 2) = 0 then
      dbms_output.put_line('now number1:' || tmp);
      dbms_output.put_line('now number2:' || tmp);
    end if;
  end loop;

  -- 游标for循环
  DBMS_OUTPUT.PUT_LINE('------------游标for循环--------------');

  declare
    cursor userinfo_cursor is
      select * from tm_employee a where a.asc_code = '4102019';
  begin
    for userinfo_rec in userinfo_cursor loop
      dbms_output.put_line('userno is:' || userinfo_rec.employee_no||  ' userno is:' || userinfo_rec.employee_name);
    end loop;
  end;

  DBMS_OUTPUT.PUT_LINE('------------当前时间--------------' || CHR(13) ||
                       to_char(nowTime, 'YYYY-MM-DD hh24:mi:ss'));
end;
 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值