0

我在 Oracle 中有一个包含 20M 条记录的表,其中包含 VARCHAR 类型的日期时间(其中一列)列和 EST 时区。我正在尝试创建一个新列,将日期时间转换为 Unix 纪元时间,但它给我一个错误。

create function unix_timestamp(pi_date date) return number is
    c_base_date constant date := to_date('1970-01-01 00:00:00', 'YYYY-MM-DD HH:MM:SS');
    c_seconds_in_day constant number := 24 * 60 * 60;
    v_unix_timestamp number;
begin
    v_unix_timestamp := trunc((pi_date - c_base_date) * c_seconds_in_day);

    if (v_unix_timestamp < 0 ) then
        raise_application_error(-20000, 'unix_timestamp:: unix_timestamp cannot be nagative');
    end if;

    return v_unix_timestamp;
end unix_timestamp;

这是我创建的函数,当我尝试调用这个函数时,它给我一个错误说:

ORA-01861: literal does not match format string
01861. 00000 -  "literal does not match format string"
*Cause:    Literals in the input must be the same length as literals in
           the format string (with the exception of leading whitespace).  If the
           "FX" modifier has been toggled on, the literal must match exactly,
           with no extra whitespace.
*Action:   Correct the format string to match the literal.

我能得到一些帮助吗?

4

1 回答 1

0

代码行

c_base_date constant date := to_date('1970-01-01 00:00:00', 'YYYY-MM-DD HH:MM:SS');

小时和分钟格式代码错误;尝试

c_base_date constant date := to_date('1970-01-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS');

MI分钟(我忘记的次数比我数的要多),并在小时格式中包含 24 ( HH24)。并查看 MathGuy 对时区的评论和对date不包括时区信息的数据类型的评论。

于 2019-07-01T15:47:19.327 回答