How to realize the sql condition of querying today's data by oracle
This article mainly introduces oracle how to achieve the sql conditions for querying the same day's data, which has a certain reference value, and interested friends can refer to it. I hope you will gain a lot after reading this article.
Daily data statistics will use the query of the current day's data, the following are the conditions for the date to be corresponding:
Between
To_date (to_char (sysdate,'yyyy-mm-dd') | |'00 and 0015 01mm hh34:mi:ss') and
To_date (to_char (sysdate,'yyyy-mm-dd') | |'23 sysdate,'yyyy-mm-dd' 59 hh34:mi:ss')
Oracle
The field type is varchar2, and the format should match the formatted style
Current day select * from table name where to_char (to_date (field name, 'yyyy-mm-dd hh34:mi:ss'),' dd') = to_char (sysdate,'dd') current week select * from table name where to_char (to_date (field name, 'yyyy-mm-dd hh34:mi:ss'),' iw') = to_char (sysdate,'iw') current month select * from table name where to_char (to_date (field name, 'yyyy-mm-dd hh34:mi:ss')) 'mm') = to_char (sysdate,'mm') current quarter select * from table name where to_char (to_date (field name,' yyyy-mm-dd hh34:mi:ss'),'Q') = to_char (sysdate,'q')
Field type is date
Current day select * from table name where to_char (field name, 'dd') = to_char (sysdate,'dd') current 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') current quarter select * from table name where to_char (field name,' q') = to_char (sysdate,'q')
SQL
Select * from table name where DATEPART (dd, field name) = DATEPART (dd, GETDATE ()) and DATEPART (mm, field name) = DATEPART (mm, GETDATE ()) and DATEPART (yy, field name) = DATEPART (yy, GETDATE ()) that 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 ()) current quarter select * from table name where DATEPART (qq, field name) = DATEPART (qq, GETDATE ()) and DATEPART (yy, field name) = DATEPART (yy, GETDATE ()) Thank you for reading this article carefully I hope the article "oracle how to realize the sql conditions for querying the same day's data" shared by the editor will be helpful to you. At the same time, I also hope that you will support us and pay attention to the industry information channel. More related knowledge is waiting for you to learn!