Lokomotywa
Lokomotywa

Reputation: 2844

add a specific column to all tables that exist in an oracle database

Is there a way to achieve this? Something like

alter table
'all_tables' add(newcol varchar2(20));

is this possible?

Upvotes: 1

Views: 2120

Answers (2)

Rob van Laarhoven
Rob van Laarhoven

Reputation: 8905

Or directly execute the alter statements using execute immediate

begin
   for i in (select table_name from user_tables)
   loop
      execute immediate 'alter table '||i.table_name||' add (newcol varchar2(20))';
  end loop;
end;
/

Upvotes: 3

davegreen100
davegreen100

Reputation: 2115

run the following in sqlplus or sql developer, and then run the output from the query

select 'alter table ' || table_name || ' add (newcol varchar2(20));'
from user_tables

Upvotes: 4

Related Questions