Ren*_*ger 5 oracle sqlplus dbms-redefinition
我有我想重新定义的下表:
create table tq84_redefinition (
id number primary key,
ts1 timestamp not null,
ts2 timestamp
);
Run Code Online (Sandbox Code Playgroud)
请注意not null
对列的约束ts1
。
使用dbms_redefinition
,我专门使用copy_constraints => true
.
create table tq84_redefinition_int (
id number, -- Note: no primary key to prevent «ORA-01408: such column list already indexed»
ts1 date,
ts2 date,
duration_minutes as ((ts2 - ts1) * 24 * 60)
);
begin
dbms_redefinition.start_redef_table(
user, 'tq84_redefinition', 'tq84_redefinition_int',
'id, ' ||
'to_date(to_char(ts1, ''ddmmyyyyhh24miss''), ''ddmmyyyyhh24miss'') ts1, ' ||
'to_date(to_char(ts2, ''ddmmyyyyhh24miss''), ''ddmmyyyyhh24miss'') ts2');
end;
/
-- set serveroutput on
declare
cnt_errors binary_integer;
begin
dbms_redefinition.copy_table_dependents(
user, 'tq84_redefinition', 'tq84_redefinition_int',
-------------------------------------------------------
copy_indexes => dbms_redefinition.cons_orig_params,
copy_triggers => true,
copy_constraints => true,
copy_privileges => true,
ignore_errors => false,
num_errors => cnt_errors,
copy_statistics => true,
copy_mvlog => false);
if cnt_errors > 0 then
dbms_output.put_line('There were ' || cnt_errors || ' errors.');
end if;
end;
/
exec dbms_redefinition.sync_interim_table(user, 'tq84_redefinition', 'tq84_redefinition_int');
exec dbms_redefinition.finish_redef_table(user, 'tq84_redefinition', 'tq84_redefinition_int');
Run Code Online (Sandbox Code Playgroud)
除了desc
在 SQL*Plus 中没有正确显示not null
约束之外,一切似乎都正常:
...> desc tq84_redefinition;
Name Null? Type
--------------------------- -------- ---------------
ID NUMBER
TS1 DATE
TS2 DATE
DURATION_MINUTES NUMBER
Run Code Online (Sandbox Code Playgroud)
然而,在某处,非空约束已经到位。我可以通过发出
select constraint_type, constraint_name, search_condition
from user_constraints
where table_name = 'TQ84_REDEFINITION';
Run Code Online (Sandbox Code Playgroud)
此外,如果我尝试插入记录 [ insert into tq84_redefinition (id) values (999999)
],我会收到(正确的)错误消息ORA-01400: cannot insert NULL into ("META"."TQ84_REDEFINITION"."TS1")
。
编辑:版本(v$version)是:
BANNER
--------------------------------------------------------------------------------
Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
PL/SQL Release 11.2.0.1.0 - Production
CORE 11.2.0.1.0 Production
TNS for 32-bit Windows: Version 11.2.0.1.0 - Production
NLSRTL Version 11.2.0.1.0 - Production
Run Code Online (Sandbox Code Playgroud)
编辑 2 @Munchi,您建议的选择语句的结果
select
column_name as "Name",
nullable as "Null?",
concat(concat(concat(data_type,'('),data_length),')') as "Type"
from
user_tab_columns
where
table_name = 'TQ84_REDEFINITION'
Run Code Online (Sandbox Code Playgroud)
是
Name N Type
------------------------------ - --------------
ID Y NUMBER(22)
TS1 Y DATE(7)
TS2 Y DATE(7)
DURATION_MINUTES Y NUMBER(22)
Run Code Online (Sandbox Code Playgroud)
Bal*_*app 11
这是一个已知的错误(不幸的是描述不是公开的):
错误:4396234 ET10.2OREDEF:*_TAB_COLUMNS 表的可空列在联机重新定义后未更新
NOT NULL 约束被复制为 NOVALIDATE,您必须手动将它们设置为 VALIDATE 状态,例如:
ALTER TABLE t84_redefenition ENABLE VALIDATE CONSTRAINT constraint_name;
Run Code Online (Sandbox Code Playgroud)
主键问题类似,但没有报告错误。但是我发现禁用并重新启用它可以解决问题。
ALTER TABLE t84_redefinition DISABLE PRIMARY KEY;
ALTER TABLE t84_redefinition ENABLE PRIMARY KEY;
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3469 次 |
最近记录: |