oracle中的in date,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

# Answer 1

4d350fd91e33782268f371d7edaa8a76.png

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);

# Answer 2

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;

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值