Oralce SQL creates the calendar information for a specified period of time, oralcesql

Source: Internet
Author: User

Oralce SQL creates the calendar information for a specified period of time, oralcesql

The creation start time is 2010 and the end time is 2100.



Create table temp_calendar as select

Min (to_char (day, 'yyyymm') month,
To_char (min (decode (weekday, 1, day), 'dd') w_7,
To_char (min (decode (weekday, 2, day), 'dd') w_1,
To_char (min (decode (weekday, 3, day), 'dd') w_2,
To_char (min (decode (weekday, 4, day), 'dd') w_3,
To_char (min (decode (weekday, 5, day), 'dd') w_4,
To_char (min (decode (weekday, 6, day), 'dd') w_5,
To_char (min (decode (weekday, 7, day), 'dd') w_6
From (select trunc (day, 'yyyy') year,
Day,
Month,
Decode (sign (rn-weekday), 1, week + 1, week) week,
Weekday,
Rn
From (select day,
To_char (day, 'mm') month,
To_char (day, 'w') week,
To_char (day, 'D') weekday,
Row_number () over (partition by to_char (day, 'mm'), to_char (day, 'w') order by day) rn
From (select trunc (to_date ('20170101', 'yyyy'), 'yyyy') + level-1 day
From dual
Connect by rownum <= trunc (to_date ('20140901', 'yyyy'), 'yyyy')-trunc (to_date ('20140901', 'yyyy '), 'yyyy')
Group by a. year, a. month, a. week
Order by a. year, a. month, a. week;
How to Write a date query statement using oralce SQL?

Select * from hr_info where to_char (comdate, 'yyyy-mm-dd') between '2017-01-01 'and '2017-01-01'

How does oralce use SQL statements to query user data from to the next day in August;

Select IMSI, bytes from session where dtcol between to_date ('2017-11-01 23:00:00 ', 'yyyy-mm-dd hh24: mi: ss ') and to_date ('2017-11-02 07:00:00 ', 'yyyy-mm-dd hh24: mi: ss ')
 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.