2620:存储过程teradata中的字符错误

时间:2018-05-15 09:58:29

标签: stored-procedures teradata

连接在select语句中起作用:

SELECT 'HELLO' || 'WORLD';

正在返回HELLOWORLD,但是当我尝试在存储过程中使用它时,如下所示:

SET Time_of_Day=TRIM(Hour_of_Day) || ' : ' || TRIM(Minute_of_Hour) || ' : ' || TRIM(Second_of_Minute);

Hour_of_Day Minute_of_Hour Second_of_Minute 是变量,我也尝试过没有TRIM:

错误

**CALL FAILED 2620:PROCEDURE_NAME:THE FORMAT OR DATA CONTAINS A BAD CHARACTER**

1 个答案:

答案 0 :(得分:1)

将字符串转换为Teradata中的时间需要两位数小时/分钟/秒:

SET Time_of_Day=TRIM(Hour_of_Day (FORMAT '99')) || ' : ' ||
                TRIM(Minute_of_Hour (FORMAT '99')) || ' : ' || 
                TRIM(Second_of_Minute (FORMAT '99'))

但是这个片段可能来自你一小时前删除的SP问题(我发布答案前几秒钟)。

不需要运行86400个单行插入,只需在单个Select中创建所有数据,例如:

SELECT
   Row_Number() Over (ORDER BY h,m,s),
   Extract(SECOND From t) AS s,
   Extract(MINUTE From t) AS m,
   Extract(HOUR From t) AS h,
   t
FROM
 (
   SELECT Cast(Begin(pd) AS TIME(0)) AS t
   FROM sys_calendar.CALENDAR
   WHERE calendar_date = Current_Date
   EXPAND ON PERIOD(Cast(Current_Date AS TIMESTAMP(0)), Cast(Current_Date + 1 AS TIMESTAMP(0))) AS pd
 ) AS dt