我有一个Teradata表,其中一列中的值是整数,我必须将其转换为HOUR(2)TO MINUTE。
我已尝试过以下声明,但收到错误,如间隔字段溢出
CAST(CAST(col1 AS DECIMAL(18,0)) * INTERVAL '0000:01' MINUTE TO SECOND AS INTERVAL HOUR(2) TO MINUTE) from table1
col1包含整数值,如5192或8734等。
答案 0 :(得分:0)
根据teradata documentation:
INTERVAL HOUR TO MINUTE
的值范围如下。
Type and Precision | Minimum Value | Maximum Value
-----------------------------------------------------------------
INTERVAL HOUR(1) TO MINUTE -'9:59' '9:59'
INTERVAL HOUR(2) TO MINUTE -'99:59' '99:59'
INTERVAL HOUR(3) TO MINUTE -'999:59' '999:59'
INTERVAL HOUR(4) TO MINUTE -'9999:59' '9999:59'
对于有问题的样本数据,输出值位于INTERVAL HOUR(2) TO MINUTE
范围内,如下所示。
SELECT CAST(CAST(5192 AS DECIMAL(18,0)) * INTERVAL '0000:01' MINUTE TO SECOND AS INTERVAL HOUR(2) TO MINUTE) AS Value1,
CAST(CAST(8734 AS DECIMAL(18,0)) * INTERVAL '0000:01' MINUTE TO SECOND AS INTERVAL HOUR(2) TO MINUTE) AS Value2;
<强>结果:强>
Value1 | Value2
--------------
1:26 2:25
您的部分转换值似乎超过99:59
,在这种情况下您必须使用上面的第3个选项。
对于给定的查询和示例数据,如果任何值大于359999
,则会失败并显示错误
&#34; 间隔字段溢出&#34;
希望这会有所帮助: - )