我的存储过程失败,我正在尝试将时间戳转换为日期。
create or replace PROCEDURE "USP_CLEAN_FOBTPP"
AS
BEGIN
INSERT INTO CLN_FOBTPP
SELECT PART_PAYMENT_ID,
ISSUING_SHOP,
TILL_NUMBER,
SLIP_NUMBER,
FOBT_NUMBER,
WHO_PAID,
to_date(WHEN_PAID,'DD-MON-YY HH24:MI:SS'),
AMOUNT_LEFT_TO_PAY,
FOBT_VALUE,
STATUS
FROM IMPORTDB.IMP_FOBTPP;
COMMIT;
END;
这是我得到的错误:
ORA-01830:日期格式图片在转换整个输入之前结束 字符串。
这是When_Paid
日期列
11-OCT-17 13.29.20.000000000
11-OCT-17 13.30.21.000000000
11-OCT-17 13.31.11.000000000
11-OCT-17 12.56.39.000000000
11-OCT-17 12.57.28.000000000
11-OCT-17 12.57.46.000000000
出了什么问题?
Source Table IMPORTDB.IMP_FOBT
Name Null? Type
------------------ ----- ------------
PART_PAYMENT_ID NUMBER(38)
ISSUING_SHOP CHAR(4)
TILL_NUMBER NUMBER(3)
SLIP_NUMBER NUMBER(38)
FOBT_NUMBER VARCHAR2(30)
WHO_PAID CHAR(20)
WHEN_PAID TIMESTAMP(6)
AMOUNT_LEFT_TO_PAY NUMBER(19,4)
FOBT_VALUE NUMBER(19,4)
STATUS CHAR(2)
Destination Table IMPORTDB.CLN_FOBTPP
Name Null? Type
------------------ -------- ------------
PART_PAYMENT_ID NOT NULL VARCHAR2(4)
ISSUING_SHOP NOT NULL VARCHAR2(4)
TILL_NUMBER NOT NULL NUMBER(3)
SLIP_NUMBER NOT NULL VARCHAR2(4)
FOBT_NUMBER NOT NULL VARCHAR2(30)
WHO_PAID NOT NULL CHAR(20)
WHEN_PAID NOT NULL DATE
AMOUNT_LEFT_TO_PAY NOT NULL NUMBER(19,4)
FOBT_VALUE NOT NULL NUMBER(19,4)
STATUS NOT NULL CHAR(2)
这是表结构。
答案 0 :(得分:1)
如果存储的数据属于timestamp
数据类型,则您需要的是CAST
,而不是TO_DATE
:
...
, cast (when_paid as date) , ...
编辑:在本答案下方的评论中,OP表示他收到的错误是小时必须在1到12之间。不确定OP做错了什么;为了证明Oracle中的cast
函数不是这种情况,这里有一个例子:
with input (ts) as (
select to_timestamp('11-OCT-17 15:35:24.000000000', 'dd-MON-rr hh24:mi:ss.ff')
from dual
)
select ts, cast(ts as date) as dt
from input;
TS DT
---------------------------- -------------------
11-OCT-17 15.35.24.000000000 2017-10-11 15:35:24
答案 1 :(得分:0)
您正尝试将TO_DATE
列与DATE
转换为插入create table source1 ( t TIMESTAMP );
create table dest1 ( t DATE );
INSERT INTO source1 VALUES(SYSTIMESTAMP);
INSERT INTO dest1 SELECT * FROM source1;
列 - 这不是必需的。这非常有效。
to_date(WHEN_PAID,'DD-MON-YY HH24:MI:SS')
PS:将此行WHEN_PAID,
更改为{{1}}