SQL error: "date format picture ends before converting entire input string"

SQL error: "date format picture ends before converting entire input string"

当我在查询中 运行 这种情况 when 语句时,我在 header 中收到错误。通常这个错误应该是由于缺少 to_date 函数导致的,但我相信我已经拥有了所需的一切,但不知道为什么我真的会收到这个。非常感谢任何帮助!

case when week=to_date('25/06/2017','YYYY/MM/DD') then 26
     when week=to_date('02/07/2017','YYYY/MM/DD') then 27
     when week=to_date('09/07/2017','YYYY/MM/DD') then 28
     when week=to_date('16/07/2017','YYYY/MM/DD') then 29
     when week=to_date('23/07/2017','YYYY/MM/DD') then 30
     when week=to_date('30/07/2017','YYYY/MM/DD') then 31
     when week=to_date('06/08/2017','YYYY/MM/DD') then 32
     when week=to_date('13/08/2017','YYYY/MM/DD') then 33
     when week=to_date('20/08/2017','YYYY/MM/DD') then 34
     when week=to_date('27/08/2017','YYYY/MM/DD') then 35
     when week=to_date('03/09/2017','YYYY/MM/DD') then 36
     when week=to_date('10/09/2017','YYYY/MM/DD') then 37
     when week=to_date('17/09/2017','YYYY/MM/DD') then 38
     when week=to_date('24/09/2017','YYYY/MM/DD') then 39
     when week=to_date('01/10/2017','YYYY/MM/DD') then 40
     when week=to_date('08/10/2017','YYYY/MM/DD') then 41
     when week=to_date('15/10/2017','YYYY/MM/DD') then 42
     when week=to_date('22/10/2017','YYYY/MM/DD') then 43
     when week=to_date('29/10/2017','YYYY/MM/DD') then 44
     when week=to_date('05/11/2017','YYYY/MM/DD') then 45
     when week=to_date('12/11/2017','YYYY/MM/DD') then 46
     when week=to_date('19/11/2017','YYYY/MM/DD') then 47
     when week=to_date('26/11/2017','YYYY/MM/DD') then 48
     when week=to_date('03/12/2017','YYYY/MM/DD') then 49
     when week=to_date('10/12/2017','YYYY/MM/DD') then 50
     when week=to_date('17/12/2017','YYYY/MM/DD') then 51
     when week=to_date('24/12/2017','YYYY/MM/DD') then 52
    else 0 end as week,

Çağdaş,把你的格式改成这样:

to_date('25/06/2017','DD/MM/YYYY')

而不是 to_date('25/06/2017','YYYY/MM/DD') 等等。由于日期格式顺序错误。

格式错误。 您可以在所有表​​达式中使用 to_date('25/06/2017','DD/MM/YYYY')

无需多次硬编码,您可以使用 TO_CHAR 函数从给定日期提取一年中的第几周。

在您的情况下,您可以使用

SELECT TO_CHAR(week,'WW') from table_name;