简体   繁体   中英

Compare date with current_date in Oracle

I can not get what is wrong in this query ( ORACLE QUERY )

SELECT *
FROM HR.CUSTOMER C
dual
WHERE CREATED_AT = current_date
;

I am getting this error

ORA-00933: SQL command not properly ended

There is a dual too many in your query.

Moreover, in Oracle current_date is not the current date for the database, but the current datetime of your session. While your database server may be in a timezone where it is currently 11 pm, it may be next day 3 am already on your PC. Whenever you spot current_date in an Oracle query it is very likely wrong.

In Oracle use sysdate for now and trunc(sysdate) for today.

select * 
from hr.customer 
where created_at = trunc(sysdate);

Since you already know the table and wanted to get all the columns from it, you need not use dual

The DUAL table is a special one-row, one-column table present by default in Oracle and other database installations. In Oracle, the table has a single VARCHAR2(1) column called DUMMY that has a value of 'X'. It is suitable for use in selecting a pseudo column such as SYSDATE or USER.

You may just use the following query instead

SELECT *
  FROM HR.CUSTOMER
 WHERE CREATED_AT = current_date;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM