SQL如何在LIKE命令中传递sysdate?

Kar*_*k M 3 sql oracle

查询结果

Select SYSDATE from DUAL
Run Code Online (Sandbox Code Playgroud)

19-JUL-19
Run Code Online (Sandbox Code Playgroud)

如何在like命令中传递此日期以提取今天日期的所有元组

桌子看起来像这样

ID             MSG_TYPE       CollectionDate
515587         GenOut         21-FEB-19 04.09.57.325772000 PM
515588         GenOut         19-JUL-19 01.06.15.307068000 PM
515589         GenOut         22-AUG-18 03.20.15.307069290 PM
515590         GenOut         19-JUL-19 12.03.09.873288000 PM
Run Code Online (Sandbox Code Playgroud)

预期结果

ID             MSG_TYPE       CollectionDate
515588         GenOut         19-JUL-19 01.06.15.307068000 PM
515590         GenOut         19-JUL-19 12.03.09.873288000 PM
Run Code Online (Sandbox Code Playgroud)

Lit*_*oot 5

不要使用LIKE

一种方法是截断collection_date,但这将禁用在该列上创建的索引。但是,如果该表中没有多少行,您将不会注意到其中的区别。

select * from your_table where trunc(collection_date) = trunc(sysdate)
Run Code Online (Sandbox Code Playgroud)

一种更安全的方法是

select * from your_table
where collection_date >= trunc(sysdate)
  and collection_date <  trunc(sysdate + 1)
Run Code Online (Sandbox Code Playgroud)