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
You can use "classic comparators" (like >, >=, <, =...) to compare 2 dates. If you have date data types : don't convert them. if you have no choice, use something like: if to_char(d1,'YYYYMMDD') > to_char(d2,'YYYYMMDD') then ... else ...
In SQL, the date value has DATE datatype which accepts date in 'yyyy-mm-dd' format. To compare two dates, we will declare two dates and compare them using the IF-ELSE statement. We can declare variables easily by using the keyword DECLARE before the variable name.
SYSDATE will give the system date of the server. CURRENT_DATE will give you the system date of the session. For example, if your oracle server is in UK, the SYSDATE will be the UK time whereas, the CURRENT_DATE will be the Indian time.
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 p.m., it may be next day 3 a.m. 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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With