SQL> CREATE OR REPLACE FUNCTION is_number (parmin VARCHAR2)今天,这个朋友在MSN上又问:如何判定一个字符是否是日期?
2 RETURN NUMBER
3 IS
4 val NUMBER;
5 BEGIN
6 val := TO_NUMBER (NVL (parmin, 'a'));
7 RETURN 1;
8 EXCEPTION
9 WHEN OTHERS
10 THEN
11 RETURN 0;
12 END;
13 / Function created.SQL> select is_number('a') from dual;IS_NUMBER('A')
--------------
0SQL> select is_number('0.998') from dual;IS_NUMBER('0.998')
------------------
1SQL> select is_number('9999999999999999') from dual;IS_NUMBER('9999999999999999')
-----------------------------
1
SQL> CREATE OR REPLACE FUNCTION is_date (parmin VARCHAR2)这两者是何其相似啊!-The End-http://www.eygle.com/archives/2007/02/is_date_or_number.Html
2 RETURN NUMBER
3 IS
4 val DATE;
5 BEGIN
6 val := TO_DATE (NVL (parmin, 'a'), 'yyyy-mm-dd hh24:mi:ss');
7 RETURN 1;
8 EXCEPTION
9 WHEN OTHERS
10 THEN
11 RETURN 0;
12 END;
13 /
Function created.
SQL> select is_date('a') from dual;IS_DATE('A')
------------
0SQL> select is_date('2004-05-05') from dual;IS_DATE('2004-05-05')
---------------------
1SQL> select is_date('2004/01/01') from dual;IS_DATE('2004/01/01')
---------------------
1SQL> select is_date('01/01/04') from dual;IS_DATE('01/01/04')
-------------------
1SQL> select is_date('01-jan-04') from dual;IS_DATE('01-JAN-04')
--------------------
1
新闻热点
疑难解答