ORACLE 学习笔记(一)
觉得应该好好总结一下,ORACLE之PL/SQL学习begin
if ... then
...
elsif ...then
...
end if;
end;
实例:
DECLAREa number;b varchar2(10);begina:=2;if a=1 thenb:='a';elsif a=2 thenb:='b';elseb:='c';end if;DBMS_OUTPUT.PUT_LINE('b is'||b);end;/有关case when
case
when.. then...
when.. then...
end case
实例
DECLAREa number;b varchar2(10);begina:=2;case when a=1 then b:='a';when a=2 then b:='b';when a=3 then b:='c';elseb:='others';end case;DBMS_OUTPUT.PUT_LINE('b is'||b);end;/
循环语句
LOOP
...
END LOOP
WHILE expression LOOP
...
END LOOP
FOR counter in start_value..end_value LOOP
...
END LOOP;
实例(用第一种方式)
declarex number;beginx:=0;loopx:=x+1;if x>=3 thenexit;end if;dbms_output.put_line('内:x='||x);end loop;dbms_output.put_line('外:x='||x);end;/用exit when方式
declarex number;beginx:=0;loopx:=x+1;exit when x>=3;dbms_output.put_line('内:x='||x);end loop;dbms_output.put_line('外:x='||x);end;/用第三种方式,注意这是reverse的俄,如果是1 to 5,就不加reverse
beginfor i in reverse 1..5loopdbms_output.put_line('i='||i);end loop;dbms_output.put_line('end of for loop');end;/
页:
[1]