1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

【SQL】関数[todate]の実行結果が正規表現の指定通りにならない

Last updated at Posted at 2019-06-25

事象:関数[todate]の実行結果が正規表現の指定通りにならない

次のクエリを投げた時、実行結果が同じになるのは何故か??

test.sql
SELECT to_date('2000-01-01 23:59:59', 'yyyy-mm-dd hh24:mi:ss') ,
       to_date('2000-01-01', 'yyyy-mm-dd') 
FROM dual;

実行環境:OSQLEdit
DB:Oracle


▼想定結果

to_date('2000-01-01 23:59:59', 'yyyy-mm-dd hh24:mi:ss') to_date('2000-01-01', 'yyyy-mm-dd')
2000-01-01 23:59:59 2000-01-01

▼実行結果

to_date('2000-01-01 23:59:59', 'yyyy-mm-dd hh24:mi:ss') to_date('2000-01-01', 'yyyy-mm-dd')
2000-01-01 2000-01-01

結論:OSQLEditの設定の問題だった。

DATE型の値を表示する際に、'yyyy-mm-dd'で表示する設定になっていたため、
年月日時分秒ミリセカンドを指定した場合と、年月日のみを指定した場合で
クエリの結果が同じであった。

ツール>オプション>設定(2)>DATE型の書式
から設定可能。


補足

DATE型の値を表示を、'yyyy-mm-dd hh24:mi:ss'で表示する設定にした場合、
下記のような実行結果になった。

test.sql
SELECT to_date('2000-01-01 23:59:59', 'yyyy-mm-dd hh24:mi:ss') ,
       to_date('2000-01-01', 'yyyy-mm-dd') 
FROM dual;

実行結果

to_date('2000-01-01 23:59:59', 'yyyy-mm-dd hh24:mi:ss') to_date('2000-01-01', 'yyyy-mm-dd')
2000-01-01 23:59:59 2000-01-01 00:00:00
1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?