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

问题描述 投票:-8回答:1
select * from TNAME where
  to_char (tran_date,'YYYY') = 2018 
sql oracle
1个回答
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>
© www.soinside.com 2019 - 2024. All rights reserved.