HiveBrain v1.2.0
Get Started
← Back to all entries
patternModerate

Why is SQL*Plus' desc table not showing not null constraints after using dbms_redefinition

Submitted by: @import:stackexchange-dba··
0
Viewed 0 times
afterwhyconstraintsshowingdbms_redefinitionsqlnullplususingdesc

Problem

I have the following table that I want to redefine:

create table tq84_redefinition (
  id number primary key,
  ts1 timestamp not null,
  ts2 timestamp
);


Please note the not null constraint on the column ts1.

Using dbms_redefinition, I specifically use 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');


Everything seems to work fine except that desc in SQL*Plus doesn't correctly display the not null constraint:

```
...> desc tq84_redefinition;
Name Null? Type
--------------------------- -------- ---------------
ID NUMBER
TS1 DATE
TS2

Solution

This is a known bug (description is not public unfortunately):

Bug:4396234 ET10.2OREDEF: NULLABLE COL OF *_TAB_COLUMNS TABLE NOT UPDATED AFTER ONLINE REDEF

The NOT NULL constraints are copied as NOVALIDATE, and you have to set them to VALIDATE state manually, e.g:

ALTER TABLE t84_redefenition ENABLE VALIDATE CONSTRAINT constraint_name;


The primary key issue is similar, but there is no bug reported for that. However I have found that disabling and reenabling it solves the problem.

ALTER TABLE t84_redefinition DISABLE PRIMARY KEY;
ALTER TABLE t84_redefinition ENABLE PRIMARY KEY;

Code Snippets

ALTER TABLE t84_redefenition ENABLE VALIDATE CONSTRAINT constraint_name;
ALTER TABLE t84_redefinition DISABLE PRIMARY KEY;
ALTER TABLE t84_redefinition ENABLE PRIMARY KEY;

Context

StackExchange Database Administrators Q#55081, answer score: 11

Revisions (0)

No revisions yet.