pl/sql学习8——流程控制语句

declare
  v_index integer;
  v_name  dept.dname%type;
  cursor c_dept is
    select dname from dept;
begin
  dbms_output.put_line('if语句控制:');
  v_index := 12;
  if v_index < -1 then
    dbms_output.put_line('v_inex<-1:' || v_index);
  elsif v_index >= -1 and v_index < 10 then
    dbms_output.put_line('v_inex>-1 and v_index<10:' || v_index);
    elsif v_index>=10 and v_index<=100 then
          null;
  else
    dbms_output.put_line('v_inex>100:' || v_index);
  end if;

  dbms_output.put_line('case语句控制:');

  case
    when v_index < -1 then
      dbms_output.put_line('v_inex<-1:' || v_index);
    when v_index < 20 then
      dbms_output.put_line('v_inex<20:' || v_index);
    when v_index < 50 then
      dbms_output.put_line('v_inex<50:' || v_index);
    else
      dbms_output.put_line('v_inex>=50:' || v_index);
    
  end case;
  dbms_output.put_line('loop循环');
  open c_dept;
  loop
    fetch c_dept
      into v_name;
    dbms_output.put_line('loop部门名:' || v_name);
    exit when c_dept%notfound;
  end loop;
  close c_dept;

  dbms_output.put_line('while循环');

  while v_index > 1 loop
    dbms_output.put_line('while:v_index值:' || v_index);
    v_index := v_index - 1;
    continue when v_index = 5;
    exit when v_index = 2;
  end loop;

  dbms_output.put_line('for循环');
  for iten in c_dept loop
    dbms_output.put_line('for部门名:' || v_name);
  end loop;
end;


 

你可能感兴趣的:(c,null,Integer)