if a='1' then null; endif;
2.Case
簡單case表達式:
搜索型Case表達式:
begin
if true then
goto label2;
end if;
<<label1>>
SYS.DBMS_OUTPUT.PUT_LINE('label1');
<<label2>>
SYS.DBMS_OUTPUT.PUT_LINE('label2');
end;
begin
FOR j IN 1..5 LOOP
dbms_output.Put_line(j);
END LOOP;
END;
end;
declare
cursor myCursor is select * from ouser;
begin
FOR s IN myCursor LOOP
dbms_output.Put_line(s.userid);
END LOOP;
END;
--只輸出偶數
begin
FOR j IN 1..100 LOOP
Continue when Mod(j,2)=1;
dbms_output.Put_line(j);
END LOOP;
end;
命名異常有名字,匿名異常只有異常代碼和消息
SQLCODE函數可以獲取最後一個異常的異常代碼,SQLERRM:異常消息
declare
myexception exception; --聲明一個命名異常
v_row Sys_ACC_User%RowType;
Pragma EXCEPTION_INIT (myexception, -20002); --將一個命名異常和一個異常代碼綁定
begin
select * into v_row from Sys_ACC_User where rownum=1;
raise myexception; --手動拋出異常
RAISE_APPLICATION_ERROR(-20001,'這是一個匿名異常,我沒有名字'); --手動拋出一個匿名異常
Exception
when no_data_Found then --捕獲名為no_data_found的異常
dbms_output.Put_line('not data found'||'異常代碼:'||SQLCODE||' 異常消息'||SQLERRM);
when myexception then --捕獲名為 myexception的異常
dbms_output.Put_line('myexception'||'異常代碼:'||SQLCODE||' 異常消息'||SQLERRM);
when others then --其他命名異常和匿名異常在這裡捕獲
dbms_output.Put_line('異常代碼:'||SQLCODE||' 異常消息'||SQLERRM);
end;
create or replace function WordCount(str in varchar2)return number --塊頭
is
numCount number default:=0;--聲明單元
begin --執行單元
return Length(LTrim(str,'0'));
Exception --異常處理單元
when others then:
SYS.DBMS_OUTPUT.PUT_LINE('error');
end ;
declare --聲明單元
v_n1 varchar2(100);
begin
--執行單元
v_n1:='20';
SYS.DBMS_OUTPUT.PUT_LINE(v_n1);
exception --異常處理單元
when others then
SYS.DBMS_OUTPUT.PUT_LINE('error');
end;
1.轉義: q’<s’d>’,表示為: s’d ,<和>必須成對出現,可用(),{},[]等代替
2.Function必須返回值,不想返回值的用Procedure
3.如果Procedure有參數(In/Out),調用方式: ProcedureName(param1,param2);如果procedure沒有參數,則直接: ProcedureName或者ProcedureName(),Function類似…
4.空字符 ’’is Null =>true
zhxjdwh:http://www.cnblogs.com/zhxj/