【发布时间】:2017-07-06 11:32:31
【问题描述】:
我尝试在 Oracle 11g.2.0.3 上创建一个 table2:
CREATE table2
LOGGING TABLESPACE TS_table1_2014 PCTFREE 10 INITRANS 1 STORAGE ( INITIAL 65536 NEXT 1048576 MINEXTENTS 1 MAXEXTENTS UNLIMITED BUFFER_POOL DEFAULT ) NOCOMPRESS
as (select * from table1 where date_text <= '2015-12-31');
当我尝试将此表 2 与分区表 3 交换时,我收到以下错误:
alter table table3 exchange partition partition_name WITH TABLE table2;
Error report -
SQL Error: ORA-14097: column type or size mismatch in ALTER TABLE EXCHANGE PARTITION
14097. 00000 - "column type or size mismatch in ALTER TABLE EXCHANGE PARTITION"
*Cause: The corresponding columns in the tables specified in the
ALTER TABLE EXCHANGE PARTITION are of different type or size
*Action: Ensure that the two tables have the same number of columns
with the same type and size.
我有以下查询的测试差异:
Select a.COLUMN_NAME
, a.DATA_TYPE, b.DATA_TYPE
, a.data_length, b.data_length
, a.data_precision, b.data_precision
, a.data_scale, b.data_scale
, a.nullable, b.nullable
from ALL_TAB_COLUMNS a
full outer join ALL_TAB_COLUMNS b on a.column_name=b.column_name
and b.owner=user and b.table_name='&table2'
where a.owner=user and a.table_name='&table1'
and (
nvl(a.data_type,'#')!=nvl(b.data_type,'#')
or nvl(a.data_length,-1)!=nvl(b.data_length,-1)
or nvl(a.data_precision,-100)!=nvl(b.data_precision,-100)
or nvl(a.data_scale,-100)!=nvl(b.data_scale,-100)
or nvl(a.nullable,'#')!=nvl(b.nullable,'#')
)
;
导致的一些差异在于列大小。这种语法“create as select”没有保持新表创建的顺序和大小。
如何从 table1 创建 table2 as select 并强制保持与主 table1 源相同大小的列?
谢谢!
【问题讨论】:
-
table1 和 table3 的 DDL 是什么?
-
在另一个具有相似表的数据集上,所有列的大小和顺序都可以使用简单的语法“create as select”创建。我怀疑分配的用户权限不同。
-
您应该像这样进行分区:VALUES LESS THAN (TO_DATE('01-01-2015','dd-mm-yyyy'))
-
table1也需要DDL或结构
标签: oracle database-administration