【问题标题】:how many ways to extract day in date column in SQL? [closed]有多少种方法可以在 SQL 中提取日期列中的日期? [关闭]
【发布时间】:2018-08-09 12:28:04
【问题描述】:
select * from TNAME where
  to_char (tran_date,'YYYY') = 2018 

【问题讨论】:

  • 您使用的是哪个 dbms?该查询是特定于产品的。
  • 如果您使用的是 MS SQL,那么此功能可能会对您有所帮助。选择日期('03-02-2018')
  • 不太了解 dbms ,正在使用 Oracle sql devloer 控制台
  • 日期函数与数据库品牌密切相关,因此您应该正确标记您的问题
  • 不清楚您实际尝试做什么或遇到什么问题。你有什么数据,你想要什么输出?

标签: sql oracle


【解决方案1】:

提取?您的代码建议 year,所以 - 我将改用 year。这里有一些选项可以做到这一点:

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>

【讨论】:

    猜你喜欢
    • 2021-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-12
    • 1970-01-01
    相关资源
    最近更新 更多