日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

oracle 正则表达式匹配日期格式,利用正则表达式找出不合符的日期

發布時間:2024/9/27 编程问答 36 豆豆
生活随笔 收集整理的這篇文章主要介紹了 oracle 正则表达式匹配日期格式,利用正则表达式找出不合符的日期 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

很多時候我們的日期可能存放的是字符串類型,在插入的時候也很有可能插入的日期格式不正確,

因此我們需要找出這些不合符的日期格式,來此來修正。當然可以使用TO_DATE函數一個一個的轉換來找出不合法的日期。ORACLE提供了正則表達式,正則表達式在處理不合符的IP ,手機號,EMAIL等大有用處。

此處我們用正則表達式找出不合法的日期格式。

SQL> conn ysp/ysp

Connected.

SQL> select * from v$version;

BANNER

----------------------------------------------------------------------------------------------------

Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi

PL/SQL Release 10.2.0.4.0 - Production

CORE??? 10.2.0.4.0????? Production

TNS for IBM/AIX RISC System/6000: Version 10.2.0.4.0 - Productio

NLSRTL Version 10.2.0.4.0 - Production

SQL> create table? regexp_test(datecol char(19));

Table created.

SQL> insert into regexp_test select LAST_DDL_TIME? from user_objects where rownum<=10;

10 rows created.

SQL> commit;

Commit complete.

SQL> select * from regexp_test;

DATECOL

--------------------------------------

2010-07-06 16:56:07

2010-06-12 16:16:36

2010-06-12 13:44:14

2010-06-12 14:23:33

2010-06-12 14:48:21

2010-07-26 10:44:27

2010-06-04 10:20:03

2010-06-04 13:22:31

2010-06-04 10:26:31

2010-06-04 13:50:02

10 rows selected.

此處我們用YYYY-MM-DD HH24:MI:SS作為我們的日期格式,其他格式為非法。

SQL> update regexp_test set datecol='2010-00-06 16:56:07' where datecol='2010-07-06 16:56:07';

1 row updated.

SQL> update regexp_test set datecol='2010-06-00 16:16:36' where datecol='2010-06-12 16:16:36';

1 row updated.

SQL> update regexp_test set datecol='2010-06-12 24:44:14' where datecol='2010-06-12 13:44:14';

1 row updated.

SQL> update regexp_test set datecol='2010-06-12 14:60:33' where datecol='2010-06-12 14:23:33';

1 row updated.

SQL> update regexp_test set datecol='2010-06-12 14:48:67' where datecol='2010-06-12 14:48:21';

1 row updated.

SQL> commit;

Commit complete.

SQL> insert into regexp_test values('2010-06-04:13:50:02');

1 row created.

SQL> commit;

Commit complete.

SQL> select * from regexp_test;

DATECOL

---------------------------

2010-00-06 16:56:07? --月份不合法

2010-06-00 16:16:36? --日子不合法

2010-06-12 24:44:14? --小時不合法

2010-06-12 14:60:33? --分鐘不合法

2010-06-12 14:48:67? --秒數不合法

2010-07-26 10:44:27

2010-06-04 10:20:03

2010-06-04 13:22:31

2010-06-04 10:26:31

2010-06-04 13:50:02

2010-06-04:13:50:02? --格式不合法

11 rows selected.

找出合法的日期

SQL> select * from regexp_test

2? where regexp_like(datecol,'^([0-9]{4})-((0[1-9])|(1[0-2]))-((0[1-9])|([1-2][0-9])|(3[0-1])) (([0-1][0-9])|(2[0-3])):([0-5][0-9]):([0-5][0-9])$');

DATECOL

--------------------------------------

2010-07-26 10:44:27

2010-06-04 10:20:03

2010-06-04 13:22:31

2010-06-04 10:26:31

2010-06-04 13:50:02

找出不合法的日期

SQL> select * from regexp_test

2? where not regexp_like(datecol,'^([0-9]{4})-((0[1-9])|(1[0-2]))-((0[1-9])|([1-2][0-9])|(3[0-1])) (([0-1][0-9])|(2[0-3])):([0-5][0-9]):([0-5][0-9])$');

DATECOL

--------------------------------------

2010-00-06 16:56:07

2010-06-00 16:16:36

2010-06-12 24:44:14

2010-06-12 14:60:33

2010-06-12 14:48:67

2010-06-04:13:50:02

6 rows selected.

總結

以上是生活随笔為你收集整理的oracle 正则表达式匹配日期格式,利用正则表达式找出不合符的日期的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。