Oracle PL/SQL: 判斷資料只有數字, 無英文字母

在 Oracle Database 中, 有時候要判斷資料中, 只要有數字, 而無英文字母,

可以利用 to_number 來幫我們實現此需求,

只要有非數字的字元存在, 則 to_number 就會有 Exception 錯誤.

 範例
declare
v_data varchar2(30) := '123abc';
begin

-- 若不是純數字, 則 to_number 時會觸發 Exception
begin
v_data := to_number(v_data);
exception when others then
v_data := 0;
end;

dbms_output.put_line( nvl(v_data,0) );
end;
Related Posts Plugin for WordPress, Blogger...