0

Our oracle db has various users with same schema. I would like to add a column to one table in those schemas. The same column to same table in every schema. I know that I can do that manually, like that

alter table user1.EMER_COMP add TELEFONE varchar2(20) NULL;

alter table user2.EMER_COMP add TELEFONE varchar2(20) NULL;

...

Is there an easier way to do this?

asked May 24, 2018 at 15:25
1
  • You can generate the SQL using a query on Oracle catalog tables. Or write a procedure that uses dynamic SQL. Commented May 24, 2018 at 15:33

1 Answer 1

0
begin
 for t in (select * from dba_tables where table_name = 'EMER_COMP')
 loop
 execute immediate 'alter table "' || t.owner || '"."' || t.table_name || '" add TELEFONE varchar2(20) NULL'; 
 end loop;
end;
/
answered May 24, 2018 at 20:59

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.