LoginSignup
7
3

More than 5 years have passed since last update.

Oracle限定:SQLだけでカレンダー出力

Posted at

ROWNUMの指定を使わなければOracle DB以外でも応用はできると思いますが、以下のSQLで任意のカレンダー出力が可能です。

SELECT 
  start_date + ROWNUM -1 calendar
FROM (
  SELECT 
    TRUNC(
      TO_DATE('20170221','YYYYMMDD')  -- 表示開始の年月日を指定
    ) start_date, 
    90 days -- 表示したい日数を指定
FROM 
  DUAL
) ,ALL_CATALOG -- 表示したい日数分の行数があるテーブルを指定 = ROUNUMで利用
WHERE 
  ROWNUM <= days

こんな方法もあるんですねぇ:sunflower:

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