Skip to content
Advertisement

In Oracle, Can you create a new table with the same groups if you use CTAS Query?

I use the query CTAS to create a new table, however, when CTAS has finished, other users can´t select the new table, but they had access to the old, Is it a way to pass all the users and groups to the new table? because the old table will be deleted.

Advertisement

Answer

“A way” is to grant (at least) select privileges to all those users.

If you used a role and granted select privilege to that role, and then granted role to those users, things would be quite simpler – just grant select privilege on the new table to the same role, and everyone will “see” it.

Otherwise, you can write query to create those grant statements for you.

For example, in Scott’s schema there’s the EMP table. I’ve previously granted privileges on it to other users in my database, and now I’m going to create a “new” CTAS table and grant privileges to the same set of users.

Now simply copy/paste the above bunch of grant statements:


If there’s zillion of users, PL/SQL option would be simpler as it would do everything for you (i.e. no copy/pasting):

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement