转帖:作者bzszp SQL> create or replace function f_str_or_num(str varchar2) return varchar2 is 2 v_num number; 3 v_return varchar2(60); 4 begin 5 v_num:=to_number(str); 6 v_return:=str||' is a number string!'; 7 return v_return; 8 exception when others then 9 v_return:=str||' is not a number string!'; 10 return v_return; 11 end f_str_or_num; 12 / Function created. SQL> select f_str_or_num('123.56') from dual; F_STR_OR_NUM('123.56') -------------------------------------------------------------------------------- 123.56 is a number string! SQL> select f_str_or_num('12aa.56') from dual; F_STR_OR_NUM('12AA.56') -------------------------------------------------------------------------------- 12aa.56 is not a number string! SQL>
SQL> create or replace function f_str_or_num(str varchar2) return varchar2 is
2 v_num number;
3 v_return varchar2(60);
4 begin
5 v_num:=to_number(str);
6 v_return:=str||' is a number string!';
7 return v_return;
8 exception when others then
9 v_return:=str||' is not a number string!';
10 return v_return;
11 end f_str_or_num;
12 / Function created. SQL> select f_str_or_num('123.56') from dual;
F_STR_OR_NUM('123.56')
--------------------------------------------------------------------------------
123.56 is a number string! SQL> select f_str_or_num('12aa.56') from dual;
F_STR_OR_NUM('12AA.56')
--------------------------------------------------------------------------------
12aa.56 is not a number string! SQL>