Oracle obtains the week start and end date based on the week

Source: Internet
Author: User

Select
The_week,
Sunday,
Saturday,
To_char (Sunday, 'yyyymmdd') | '-' | to_char (Saturday, 'yyyymmdd') week_desc

From (select Sunday. the_week,
Decode (sign (Sunday. the_day-Saturday. the_day ),
-1,
Sunday. the_day,
Sunday. the_day-7) Sunday,
Saturday. the_day Saturday
From (select decode (to_char (wwm, 'yyyy/mm/dd'), '2014/1/01 ', '1', to_char (wwm, 'ww') + 1) the_week,
To_char (wwm, 'D') the_daynum,
Wwm the_day
From (select trunc (to_date ('1970-01-01 ', 'yyyy-mm-dd'), 'mm') + rownum-1 as wwm
From user_objects
Where rownum <366)
Where to_char (wwm, 'D') = 1 or to_char (wwm, 'yyyy/mm/dd') = '2017/01 ') Sunday,
(Select to_char (wwm, 'ww ') + 0 the_week,
To_char (wwm, 'D') the_daynum,
Wwm the_day
From (select trunc (to_date ('1970-01-01 ', 'yyyy-mm-dd'), 'mm') + rownum-1 as wwm
From user_objects
Where rownum <366)
Where to_char (wwm, 'D') = 7 or to_char (wwm, 'yyyy/mm/dd') = '2017/31') Saturday
Where Sunday. the_week = Saturday. the_week)

Where THE_WEEK =?

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.