1
1

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で擬似カレンダーテーブルを作成するメモ

Last updated at Posted at 2019-06-26

週間,月間帳票系で日付のテーブルを作ってFROM句のメインにに添えたくなるが、
作成自体は簡単なクエリで作成できるのでメモ

SELECT TRUNC(SYSDATE,'MONTH') + LEVEL -1 AS DAYS
  FROM DUAL
CONNECT BY LEVEL <= LAST_DAY(SYSDATE) - TRUNC(SYSDATE,'MONTH') +1

月末月初の差分を取得してlevelのところで対応といった形、
これで当月の1日~月末までの疑似テーブルの生成が可能。

もしPJでカレンダーテーブルを作る等の話が出ていれば、
個人的には疑似テーブルを作るfunctionを生成して、登録した情報のみをDBに入れるほうが
好みなので検討してみてください。

1
1
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
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?