运行以下内容:
CREATE OR REPLACE TYPE MT_TIMESTAMP_ERROR_TYPE
IS OBJECT
(
ID VARCHAR(10),
TIMEST TIMESTAMP
)
;
CREATE TABLE MT_TIMESTAMP_ERROR_TABLE
(
ecid VARCHAR(10),
startdate DATE
)
;
CREATE OR REPLACE VIEW MT_TIMESTAMP_ERROR_VIEW
OF MT_TIMESTAMP_ERROR_TYPE
WITH OBJECT IDENTIFIER(ID)
AS
(
select
ecid AS ID,
CAST(startdate as TIMESTAMP) AS TIMEST
from MT_TIMESTAMP_ERROR_TABLE
);
我得到了:
Error at Command Line : 23 Column : 5
Error report -
SQL Error: ORA-00932: inconsistent datatypes: expected TIMESTAMP got TIMESTAMP
00932. 00000 - "inconsistent datatypes: expected %s got %s"
*Cause:
*Action:
Oracle版本: Oracle Database 11g企业版11.2.0.3.0版 - 64位生产
可能是什么问题?
谢谢!
的问候,安德拉什
答案 0 :(得分:2)
您需要视图的对象构造函数。该表在每行中不包含两列。它包含一个具有两个值的对象。所以:
CREATE OR REPLACE VIEW MT_TIMESTAMP_ERROR_VIEW
OF MT_TIMESTAMP_ERROR_TYPE
WITH OBJECT IDENTIFIER(ID)
AS
(
select MT_TIMESTAMP_ERROR_TYPE(ecid, CAST(startdate as TIMESTAMP))
from MT_TIMESTAMP_ERROR_TABLE
);
Here是一个SQL小提琴。
或者,如果要从对象中提取两个字段,则不要声明视图以返回对象:
CREATE OR REPLACE VIEW MT_TIMESTAMP_ERROR_VIEW
AS
(
select t.ecid, t.startdate
from MT_TIMESTAMP_ERROR_TABLE t
);
PS。我不知道为什么Oracle会给出这样一个令人困惑的错误消息。它应该更像是"不一致的数据类型:预期的MT_TIMESTAMP_ERROR_TYPE得到了TIMESTAMP"。据推测,错误处理系统在不同类型的类别上变得混乱。