在SQL中提取日期列的日期有多少种方法?

时间:2018-03-01 12:23:04

标签: sql oracle

select * from TNAME where
  to_char (tran_date,'YYYY') = 2018 

1 个答案:

答案 0 :(得分:1)

提取?您的代码建议,所以 - 我将使用。以下是一些选项:

SQL> select count(*) from dual where extract(year from sysdate) = 2018;

  COUNT(*)
----------
         1

SQL> select count(*) from dual where to_char(sysdate, 'yyyy') = '2018';

  COUNT(*)
----------
         1

SQL> select count(*) from dual where trunc(sysdate, 'yyyy') = date '2018-01-01';

  COUNT(*)
----------
         1

SQL>