如何将包含dd.mm.yyyy格式的日期的varchar值转换为日期格式' yyyy-mm-dd'在Teradata的WHERE子句中? 需要编写类似的代码:
SELECT * from TABLE
WHERE <some operations with VARCHAR variable containing date> between '2015-06-01' and '2017-12-31'
答案 0 :(得分:3)
您需要在演员表中应用格式,Teradata样式:
WHERE CAST(str AS DATE FORMAT 'dd.mm.yyyy')
BETWEEN DATE '2015-06-01' AND DATE '2017-12-31'
或Oracle风格:
WHERE TO_DATE(str, 'dd.mm.yyyy')
BETWEEN DATE '2015-06-01' AND DATE '2017-12-31'
顺便说一句,我在字符串前添加了DATE
,它是推荐(并且始终可靠)编写日期文字的方式。