Oracle queries all records for the day, week, month, and quarter __oracle

Source: Internet
Author: User
Tags getdate
Oracle
field type is VARCHAR2, format to match formatted style
That day
SELECT * FROM table name where To_char (to_date (field name, ' Yyyy-mm-dd hh24:mi:ss '), ' DD ') =to_char (sysdate, ' DD ')
When the week
SELECT * FROM table name where To_char (to_date (field name, ' Yyyy-mm-dd hh24:mi:ss '), ' IW ') =to_char (sysdate, ' IW ')
Month
SELECT * FROM table name where To_char (to_date (field name, ' Yyyy-mm-dd hh24:mi:ss '), ' mm ') =to_char (sysdate, ' mm ')
When the quarter
SELECT * FROM table name where To_char (to_date (field name, ' Yyyy-mm-dd hh24:mi:ss '), ' Q ') =to_char (sysdate, ' Q ')

field type is date
That day
SELECT * FROM table name where To_char (field name, ' DD ') =to_char (sysdate, ' DDS ')
When the week
SELECT * FROM table name where To_char (field name, ' IW ') =to_char (sysdate, ' IW ')
Month
SELECT * FROM table name where To_char (field name, ' mm ') =to_char (sysdate, ' ' mm ')
When the quarter
SELECT * FROM table name where To_char (field name, ' Q ') =to_char (sysdate, ' Q ')


Sql
That day
SELECT * FROM table name where DATEPART (dd, field name) = DATEPART (dd, GETDATE ()) and DATEPART (mm, field name) = DATEPART (mm, GETDATE ()) and DATE Part (yy, field name) = DATEPART (yy, GETDATE ())
When the week
SELECT * FROM table name where DATEPART (wk, field name) = DATEPART (wk, GETDATE ()) and DATEPART (yy, field name) = DATEPART (yy, GETDATE ())
Month
SELECT * FROM table name where DATEPART (mm, field name) = DATEPART (mm, GETDATE ()) and DATEPART (yy, field name) = DATEPART (yy, GETDATE ())
When the quarter
SELECT * FROM table name where DATEPART (QQ, field name) = DATEPART (QQ, GETDATE ()) and DATEPART (yy, field name) = DATEPART (yy, GETDATE ())
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.