Query statement for cascading padding of year, month, and day in Oracle

Source: Internet
Author: User

In the query module of the latest project, the query condition uses the year, month, and day drop-down boxes. By default, data must be filled in the drop-down boxes, which are year, month, and day, and cascade requirements must be met. In this case, you need to fill in the month data based on different years and fill in different days for different months. The filled data needs to be queried using the statement. The desired result is finally achieved through hard work, as shown below:

1. Year:

 
Select (1-level + to_char (sysdate, 'yyyy') years from dualconnect by level <= 10

2. month:

 
Select case when Mons <10 then '0' | Mons else to_char (Mons) end monsnew from (select (1-level + decode (to_char (sysdate, 'yyyy '), '? Year ', -- parameter, this year only fills in the time to_char (sysdate, 'mm'), 12) Mons from dualconnect by level <= decode (to_char (sysdate, 'yyyy '),'? Year ', to_char (sysdate, 'mm'), 12 ))

3. Date:

Select case when days <10 then '0' | days else to_char (days) end daysnew from (select (1-level + decode (to_char (sysdate, 'yyyy '), '? Year ', decode (to_char (sysdate, 'mm '),'? Month ', to_number (to_char (sysdate, 'dd'), to_number (to_char (last_day (to_date ('? Year? Month '', 'yyyymmm '), 'dd'), to_number (to_char (last_day (to_date ('? Year? Month '', 'yyyymmm '), 'dd') days from dualconnect by level <= decode (to_char (sysdate, 'yyyy '),'? Year ', decode (to_char (sysdate, 'mm'), '08', to_number (to_char (sysdate, 'dd'), to_number (to_char (last_day (to_date ('? Year? Month ', 'yyyymmm'), 'dd'), to_number (to_char (last_day (to_date ('? Year? Month '', 'yyyymmm '), 'dd '))))

 

I think this statement is very useful. If you have other good statements, I hope you can share them ~~~

 

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.