Oracle筆記之三(Oracle中控制語句)

13. Oracle 中邏輯控制語句
	If elsif else end if
	set serverout on;
	declare per_dep_count number;
	begin
			select count(*) into per_dep_count from emp;
			if per_dep_count>0 then
			   dbms_output.put_line('Big Than 0');
			  elsif per_dep_count>5 then --elsif not elseif!!!!
				dbms_output.put_line('Big Than 5');
			  else
				dbms_output.put_line('En?');
			end if;
	end;
14.Case when 的使用的兩種方式
	(1)
		declare per_dep_count number;
		begin
				select count(*) into per_dep_count from emp;
				case per_dep_count
					  when 1 then
						   dbms_output.put_line('1');
					  when 2 then
						   dbms_output.put_line('2');
					  else
						   dbms_output.put_line('else');
				end case;
		end;
	(2)
		declare per_dep_count number;
			begin
			select count(*) into per_dep_count from emp;
			case 
				when per_dep_count=1 then
				   dbms_output.put_line('1');
				when per_dep_count=2 then
				   dbms_output.put_line('2');
				else
				   dbms_output.put_line('else');
					end case;
			end;
14. While 的使用
	declare v_id number:=0;
	begin
		   while v_id<5 loop
			 v_id:=v_id+1;
			 dbms_output.put_line(v_id);
			 end loop;
	end;
15.For的使用
	declare v_id number:=0;
	begin
       for v_id in 1..5 loop
       
       dbms_output.put_line(v_id);
  		 end loop;
	end;

 
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章