简体   繁体   中英

Oracle : Create table in another schema and grant select and insert on it from the same schema

I have two schemas.

1.Schema A

2.Schema B

I need to do following.

  1. I want create some tables in schema B (same as some tables in A )
  2. Then Move data from A to B .

Now I want to do ALL this from schema A . I have written a package which when executed in A will create all the tables in B and then create synonyms for them in A . And then will just select data from its own tables and insert into B's tables.

VERY IMP : Now this entire thing has to happen in one go. Just an execution of one begin block should do the entire job.

Problem : But now the synonyms would not work because Schema A does not have any privs on the tables it created in B .

so is there a way to create tables (from A to B ) with all the privs given at the creation time ? Or can the schemas be switched in PL-SQL while execution so that privs can be granted from B to A ? (I am sure this can not be done, but nothing is impossible they say ! :O :P so asking )

Please help me guys ! All suggestions are welcome !

The Main objective of this job is to do it in one go and from only one schema.

You can define a procedure which will run under definer rights, instead of caller rights

CREATE OR REPLACE PROCEDURE definer_test AUTHID DEFINER IS 
BEGIN
    ...
END definer_test;

You would define such a procedure in schema B, which does the job and call it from schema A.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM