gpt4 book ai didi

oracle - 尝试将日期值插入新表时出错(ORA-01858 : a non-numeric character was found where a numeric was expected )

转载 作者:行者123 更新时间:2023-12-03 08:08:00 33 4
gpt4 key购买 nike

我正在尝试将值插入到表中,但我不断收到错误消息

ORA-01858: a non-numeric character was found where a numeric was expected

这是我的代码:
INSERT INTO PRODUCT_DIM_HIS
(PRODUCTKEY, PRODUCTID, PRODUCTDESCRIPTION, PRODUCTLINEID, PRODUCTLINENAME, EFF_START_DATE, EFF_END_DATE)
SELECT PRODUCT_KEY_SEQ.NEXTVAL, nvl(to_char(p.PRODUCTID), 'Undefined'), nvl(to_char(p.PRODUCTDESCRIPTION), 'Undefined'),
nvl(to_char(p.PRODUCTLINEID), 'Undefined'), nvl(to_char(pl.PRODUCTLINENAME), 'Undefined'),
nvl(to_date(o.ORDERDATE), 'Undefined'), nvl(to_date(o.FULFILLMENTDATE), 'Undefined')
FROM PRODUCTLINE_T pl, PRODUCT_T p, ORDER_T o, ORDERLINE_T ol
WHERE p.PRODUCTLINEID = pl.PRODUCTLINEID
AND o.ORDERID = ol.ORDERID
AND ol.PRODUCTID = p.PRODUCTID;

要求的PRODUCT_DIM_HIS CODE:
CREATE TABLE PRODUCT_DIM_HIS
(
PRODUCTKEY integer NOT NULL,
PRODUCTID integer,
PRODUCTDESCRIPTION VARCHAR2(50 BYTE),
PRODUCTLINEID integer,
PRODUCTLINENAME VARCHAR2(50 BYTE),
EFF_START_DATE DATE,
EFF_END_DATE DATE,
CONSTRAINT PRODUCT_DIM_HIS_PK PRIMARY KEY (PRODUCTKEY)
);

来自ORDER_T的ORDERDATE和FULLFILlMENTDATE具有DATE数据类型,所以我不明白问题是什么?

@BOB_JARVIS
CREATE TABLE PRODUCT_DIM
(
PRODUCTKEY integer NOT NULL,
PRODUCTID integer,
PRODUCTDESCRIPTION VARCHAR2(50 BYTE),
PRODUCTLINEID integer,
PRODUCTLINENAME VARCHAR2(50 BYTE),
CONSTRAINT PRODUCT_DIM_PK PRIMARY KEY (PRODUCTKEY)
);

INSERT INTO PRODUCT_DIM
(PRODUCTKEY, PRODUCTID, PRODUCTDESCRIPTION, PRODUCTLINEID, PRODUCTLINENAME)
SELECT PRODUCT_KEY_SEQ.NEXTVAL, nvl(to_char(p.PRODUCTID), 'Undefined'), nvl(to_char(p.PRODUCTDESCRIPTION), 'Undefined'),
nvl(to_char(p.PRODUCTLINEID), 'Undefined'), nvl(to_char(pl.PRODUCTLINENAME), 'Undefined')
FROM PRODUCTLINE_T pl, PRODUCT_T p
WHERE p.PRODUCTLINEID = pl.PRODUCTLINEID;

INSERT INTO PRODUCT_DIM
(PRODUCTKEY, PRODUCTID, PRODUCTDESCRIPTION, PRODUCTLINEID, PRODUCTLINENAME)
VALUES (PRODUCT_KEY_SEQ.NEXTVAL, -99, 'Undefined', -99, 'Undefined');

最佳答案

删除NVL()并只保留to_date():

因此,

INSERT INTO PRODUCT_DIM_HIS
(PRODUCTKEY, PRODUCTID, PRODUCTDESCRIPTION, PRODUCTLINEID, PRODUCTLINENAME, EFF_START_DATE, EFF_END_DATE)
SELECT PRODUCT_KEY_SEQ.NEXTVAL, nvl(to_char(p.PRODUCTID), 'Undefined'), nvl(to_char(p.PRODUCTDESCRIPTION), 'Undefined'),
nvl(to_char(p.PRODUCTLINEID), 'Undefined'), nvl(to_char(pl.PRODUCTLINENAME), 'Undefined'),
to_date(o.ORDERDATE), to_date(o.FULFILLMENTDATE)
FROM PRODUCTLINE_T pl, PRODUCT_T p, ORDER_T o, ORDERLINE_T ol
WHERE p.PRODUCTLINEID = pl.PRODUCTLINEID
AND o.ORDERID = ol.ORDERID
AND ol.PRODUCTID = p.PRODUCTID;

关于oracle - 尝试将日期值插入新表时出错(ORA-01858 : a non-numeric character was found where a numeric was expected ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47543580/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com