oracle条件判断语句以及goto和null

本文详细介绍了 Oracle 数据库中 PL/SQL 的控制语句使用方法,包括 if...then、if...then else、if...then elsif...then else 语句的使用场景及示例,以及 loop、while 和 for 循环的用法,并展示了 goto 和 null 的使用方式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 //if  then  
 create or replace procedure sp_test(num number)
 is 
  --定义部分
 begin
  --执行部分
	 if num=1 then
	  dbms_output.put_line('等于1');
	 end if;
 end;
 //  if .. then else
 create or replace procedure sp_test(num number)
 is 
   --定义部分
 begin
 --执行部分
	 if num=1 then
	  dbms_output.put_line('等于1');
	 else 
	   dbms_output.put_line('不等于1');
	 end if;
 end;
  //  if .. then elsif..then elsif.. then else
 create or replace sp_test(num number)
 is 
  --定义部分
 begin
  --执行部分
	 if num=1 then
	   dbms_output.put_line('等于1');
	 elsif num=2 then 
	   dbms_output.put_line('等于2');
	 elsif num=3 then
	    dbms_output.put_line('等于3');
	  else
	   dbms_output.put_line('不等于1,2,3');
	 end if;
 end;
 //loop	循环,无论如何都会先执行一次,相当与java中的do{} while();
  create or replace procedure sp_test(num varchar2)
 is 
 --定义部分
 v_num number:=1;
 begin
 --执行部分
	 loop
		insert into user(v_num,name);
		exit when v_num<=10;--退出的条件
		v_num:=v_num+1; --自增
	 end loop;
 end;

  //while 循环
  create or replace procedure sp_test(num varchar2)
 is 
 --定义部分
 v_num number:=1;
 begin
 --执行部分
	while v_num<=10 loop
		insert into user(v_num,name);
		exit when v_num<=10;--退出的条件
		v_num:=v_num+1; --自增
	 end loop;
 end;
 // for  循环
  //while 循环
  create or replace procedure sp_test(num varchar2)
 is 
 --定义部分
 v_num number:=6;
 begin
 --执行部分
	for i in 1..v_num loop --表示从1开始自增
	      insert into user(i,name);
	end loop;
 end;
 oracle 中的goto和null;//goto
declare
v_num int:=1;
begin
	loop
	if v_num=5 then
	 goto end_loop;--跳到指定的goto标志处
	else
	    v_num:=v_num+1;
	end if;
	end loop;
	dbms_output.put_line('v_num'||5);
	<<end_loop>>	--跳到这里
       dbms_output.put_line('结束');
end;
//输出,不会输出 结束
5
//null
declare
v_num int:=1;
begin
	if v_num=5 then
	 dbms_output.put_line('是'||v_num);
	else
	  null;--主要还是为了增加程序的可读性
	end if;
end;
 


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值