I am attempting to write an sql command into an sql file so that the output itself can be used as a script. Basically using a script to create output that is itself formatted into runnable script. Maybe it's redundant but I haven't been able to think of a better way. I could use an extra set of eyes (or ideas) if possible. Thanks
Here's the script:
CONNECT &&master_user/&&master_pwd.@&&tns_alias
SET LINESIZE 132 PAGESIZE 0 ECHO OFF FEEDBACK OFF
SET VERIFY OFF HEAD OFF TERM OFF TRIMSPOOL ON
SPO syns_list.sql
--GRANT CREATE ANY SYNONYM TO &&syn_user;//how is this line formed?
select 'create or replace synonym ' || table_name ||
' for ' || '&&master_user..' ||
table_name || ';'
from user_tables
order by table_name asc;
--REVOKE CREATE ANY SYNONYM FROM &&syn_user;//how is this line formed?
SPO OFF;
SET ECHO ON FEEDBACK ON VERIFY ON HEAD ON TERM ON;
exit
This is the output:
//need the "grant" line here
create or replace synonym AGENTS for webdemo_admin.AGENTS;
create or replace synonym CONSTRUCTION_COMPANY for webdemo_admin.CONSTRUCTION_COMPANY;
create or replace synonym CONTRACT for webdemo_admin.CONTRACT;
create or replace synonym CUSTOMERS for webdemo_admin.CUSTOMERS;
create or replace synonym CUSTOMER_INTEREST for webdemo_admin.CUSTOMER_INTEREST;
create or replace synonym FEATURE for webdemo_admin.FEATURE;
create or replace synonym HOME for webdemo_admin.HOME;
create or replace synonym HOME_NONSTD_FEATURE for webdemo_admin.HOME_NONSTD_FEATURE;
create or replace synonym INTEREST for webdemo_admin.INTEREST;
create or replace synonym NON_STD_FEATURE for webdemo_admin.NON_STD_FEATURE;
create or replace synonym SALES for webdemo_admin.SALES;
create or replace synonym STD_FEATURE for webdemo_admin.STD_FEATURE;
create or replace synonym STD_MODEL for webdemo_admin.STD_MODEL;
create or replace synonym STD_MODEL_FEATURE for webdemo_admin.STD_MODEL_FEATURE;
create or replace synonym SUB_CONTRACTOR for webdemo_admin.SUB_CONTRACTOR;
create or replace synonym WARRANTY_WORK for webdemo_admin.WARRANTY_WORK;
//need the "revoke" line here
I am sure there are better ways to do this, I'm still picking things up as I go. As fo an explanation (for understanding): I want that I maintain a user with full control over the tables (and the schema) but I need a user (or upto 10 users) with the above-listed private synonyms in order for multiple connections to have the same type of access that a real-estate agent might (when viewing this from the perspective of a web app). That is, the synonyms allow for select,insert, update and delete transactions. The reason for the grant/revoke before and after the synonym creation is only to automate the process and remove the security problem of granting the create any synonym to a normal user. Further, I do not want the synonyms to be public as that is also a headache to keep track of (and again a security problem). In any case, private is better and offers more control.
Again, I appreciate any suggestions anyone may have.