Oracle
 sql >> डेटाबेस >  >> RDS >> Oracle

दो तिथियों के बीच महीने का नाम, दिन का नाम, सप्ताह संख्या और दिन संख्या उत्पन्न करें

पंक्ति जनरेटर का उपयोग करना आसान होना चाहिए तरीका। बाकी सिर्फ फॉर्मेट मास्क है ।

एसक्यूएल*प्लस . में , मेरा डेमो दिनांकों के बीच है '2012-01-01' और '2012-02-20' :

SQL> def date_start = '2012-01-01'
SQL> def date_end   = '2012-02-20'
SQL>
SQL> WITH DATA AS
  2    (SELECT to_date('&date_start', 'YYYY-MM-DD') date1,
  3      to_date('&date_end', 'YYYY-MM-DD') date2
  4    FROM dual
  5    )
  6  SELECT TO_CHAR(date1+LEVEL-1, 'fmMonth') month_name,
  7         TO_CHAR(date1+LEVEL-1, 'fmDay') day_name,
  8         TO_CHAR(date1+LEVEL-1, 'IW') the_week,
  9         TO_CHAR(date1+level-1, 'D') the_day
 10  FROM data
 11    CONNECT BY LEVEL <= date2-date1+1
 12  /
old   2:   (SELECT to_date('&date_start', 'YYYY-MM-DD') date1,
new   2:   (SELECT to_date('2012-01-01', 'YYYY-MM-DD') date1,
old   3:     to_date('&date_end', 'YYYY-MM-DD') date2
new   3:     to_date('2012-02-20', 'YYYY-MM-DD') date2

परिणाम

MONTH_NAME DAY_NAME  THE_WEEK THE_DAY
---------- --------- -------- -------
January    Sunday    52       1
January    Monday    01       2
January    Tuesday   01       3
January    Wednesday 01       4
January    Thursday  01       5
January    Friday    01       6
January    Saturday  01       7
January    Sunday    01       1
January    Monday    02       2
January    Tuesday   02       3
January    Wednesday 02       4
January    Thursday  02       5
January    Friday    02       6
January    Saturday  02       7
January    Sunday    02       1
January    Monday    03       2
January    Tuesday   03       3
January    Wednesday 03       4
January    Thursday  03       5
January    Friday    03       6
January    Saturday  03       7
January    Sunday    03       1
January    Monday    04       2
January    Tuesday   04       3
January    Wednesday 04       4
January    Thursday  04       5
January    Friday    04       6
January    Saturday  04       7
January    Sunday    04       1
January    Monday    05       2
January    Tuesday   05       3
February   Wednesday 05       4
February   Thursday  05       5
February   Friday    05       6
February   Saturday  05       7
February   Sunday    05       1
February   Monday    06       2
February   Tuesday   06       3
February   Wednesday 06       4
February   Thursday  06       5
February   Friday    06       6
February   Saturday  06       7
February   Sunday    06       1
February   Monday    07       2
February   Tuesday   07       3
February   Wednesday 07       4
February   Thursday  07       5
February   Friday    07       6
February   Saturday  07       7
February   Sunday    07       1
February   Monday    08       2

51 rows selected.

SQL>



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Oracle JDBC आंतरायिक कनेक्शन समस्या

  2. तुलना करने के लिए CLOB को NUMBER में कनवर्ट करना - Oracle

  3. शालीनता की ओर जाता है:जोखिम वास्तविकता बन जाता है

  4. Oracle त्रुटि ORA-06512

  5. पीएल/एसक्यूएल - पाइपलाइन किए गए फ़ंक्शन में तत्काल निष्पादित करें