MODIFY COLUMN in oracle – How to check if a column is nullable before setting to nullable?

You could do this in PL/SQL:

declare
  l_nullable user_tab_columns.nullable%type;
begin
  select nullable into l_nullable
  from user_tab_columns
  where table_name="MYTABLE"
  and   column_name="MYCOLUMN";

  if l_nullable="N" then
    execute immediate 'alter table mytable modify (mycolumn null)';
  end if;
end;

Leave a Comment