PL/SQL 不仅提供了条件分支语句和循环控制语句,而且还提供了循环控制语句goto和null 。但与if,case,和loop语句不同,goto语句和null语句不是非常重要,一般情况下这两种语句不需要使用。


goto语句用于跳转到特定处执行语句。注意,因为使用goto语句会增加程序的复杂度,而且使得应用程序可读性非常差,所以开发应用程序一般不建议使用goto语句。


例子:

declare
i int:=1;
begin loop
insert into temp values(i);
if i=10 then goto end_loop;
end if;
i:=i+1;
end loop;
<<end_loop>>
dbms_output.put_line('循环结束');
end;
/

 


null语句不会执行任何操作,而且会直接将控制场地倒下一条语句。使用null语句的好处是可以提高pl/sql程序的可读性。

例子:

declare 
v_sal emp.sal%type;
v_ename emp.ename%type;
begin
select ename,sal into v_ename,v_sal
from emp where empno=&no;
if v_sal<3000 then 
update emp set comm=sal*0.1 where ename=v_ename;
else
   null;
end if;
end;
/

输入no的值:7788


 

相关文章:

  • 2022-12-23
  • 2021-06-27
  • 2021-09-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-28
  • 2021-11-09
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-29
  • 2022-02-20
  • 2021-12-04
  • 2021-04-15
  • 2021-12-07
相关资源
相似解决方案