{"id":14,"date":"2011-10-24T20:23:00","date_gmt":"2011-10-24T20:23:00","guid":{"rendered":"https:\/\/bijoos.com\/oraclenotes\/?p=14"},"modified":"2026-02-07T15:29:24","modified_gmt":"2026-02-07T21:29:24","slug":"script-to-grant-privileges-and-create-synonyms","status":"publish","type":"post","link":"https:\/\/bijoos.com\/oraclenotes\/2011\/14\/","title":{"rendered":"Script to Grant Privileges and Create Synonyms"},"content":{"rendered":"<div dir=\"ltr\" trbidi=\"on\">Extending the previous post\u00a0<span><span><a href=\"http:\/\/bt-oracle.blogspot.com\/2011\/10\/granting-privileges-on-all-or-multiple.html\">Granting privileges on all or multiple objects to user\/role<\/a><\/span><\/span>\u00a0, here is another script.<\/p>\n<p>Often we have a requirement to create read only accounts for a schema. Typically these accounts are named <schema>_QUERY. The script when executed will prompt for the user name of the read only account, and the schema name where read privileges on the objects to be granted. It produces output to the screen and writes to file named tmpgrants.sql. Execute the tmpgrants.sql to grant SELECT privilege and to create a synonym under the read only account, so that the query account need not worry about qualifying the table with schema name.<\/schema><\/p>\n<p>First create the read only user account using similar syntax as below&#8230;<\/p>\n<p><span>create user tdmaa_query identified by tdm123q default tablespace users;<\/span><br \/><span>grant create session to tdmaa_query;<\/span><\/p>\n<p>Be sure to save all the below lines to a file and run the file in SQL*Plus&#8230; Executing this script will produce a script file named tmpgrants.sql. Run that script to grant privileges and create synonyms.<\/p>\n<p><span>set pages 0 lines 200 trims on verify off feedback off<\/span><br \/><span><br \/><\/span><br \/><span>accept grants_to \u00a0prompt &#8216;Enter user to grant privileges: &#8216;<\/span><br \/><span>accept schema \u00a0 \u00a0 prompt &#8216;Enter schema on which to grant: &#8216;<\/span><br \/><span><br \/><\/span><br \/><span>spool tmpgrants.sql<\/span><br \/><span><br \/><\/span><br \/><span>select &#8216;grant select on &#8216;||owner||&#8217;.&#8217;||table_name ||&#8217; to &#038;grants_to;&#8217;, chr(10),<\/span><br \/><span>\u00a0 \u00a0 \u00a0 \u00a0&#8216;create synonym &#038;grants_to..&#8217;||table_name ||&#8217; for &#8216;||owner||&#8217;.&#8217;||table_name||&#8217;;&#8217;, chr(10)<\/span><br \/><span>from \u00a0dba_tables<\/span><br \/><span>where owner = upper(&#8216;&#038;schema&#8217;)<\/span><br \/><span>union all<\/span><br \/><span>select &#8216;grant select on &#8216;||owner||&#8217;.&#8217;||view_name ||&#8217; to &#038;grants_to;&#8217;, chr(10),<\/span><br \/><span>\u00a0 \u00a0 \u00a0 \u00a0&#8216;create synonym &#038;grants_to..&#8217;||view_name ||&#8217; for &#8216;||owner||&#8217;.&#8217;||view_name||&#8217;;&#8217;, chr(10)<\/span><br \/><span>from \u00a0dba_views<\/span><br \/><span>where owner = upper(&#8216;&#038;schema&#8217;)<\/span><br \/><span>;<\/span><br \/><span><br \/><\/span><br \/><span>spool off<\/span><br \/><span><br \/><\/span><br \/><span>set pages 99 lines 80 verify on feedback on<\/span><br \/><span><br \/><\/span><br \/><span>prompt &#8220;Run tmpgrants.sql if you are satistified with the script&#8230;&#8221;<\/span><\/p>\n<p>Enjoy!<\/p>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Extending the previous post\u00a0Granting privileges on all or multiple objects to user\/role\u00a0, here is another script. Often we have a requirement to create read only accounts for a schema. Typically these accounts are named _QUERY. The script when executed will prompt for the user name of the read only account, and the schema name where &#8230; <a title=\"Script to Grant Privileges and Create Synonyms\" class=\"read-more\" href=\"https:\/\/bijoos.com\/oraclenotes\/2011\/14\/\" aria-label=\"Read more about Script to Grant Privileges and Create Synonyms\">Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_hide_featured_image":false,"_jetpack_featured_image_duplicate_dismissed":0,"_jetpack_feature_clip_id":0,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_post_was_ever_published":false},"categories":[133],"tags":[],"class_list":["post-14","post","type-post","status-publish","format-standard","hentry","category-oracledb"],"acf":[],"jetpack-related-posts":[{"id":15,"url":"https:\/\/bijoos.com\/oraclenotes\/2011\/15\/","url_meta":{"origin":14,"position":0},"title":"Granting privileges on all or multiple objects to user\/role","author":"Biju","date":"October 18, 2011","format":false,"excerpt":"Granting privileges on all or multiple objects to user\/roleQuestion:I need to grant SELECT, UPDATE privilege on all tables owned by schema XXVMX to users MSUBBU, SMARTIN. Is there a command in Oracle to grant a privilege on all objects in schema to user?Answer:No such privilege in Oracle. You will have\u2026","rel":"","context":"In &quot;Oracle Database&quot;","block_context":{"text":"Oracle Database","link":"https:\/\/bijoos.com\/oraclenotes\/category\/oracledb\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2210,"url":"https:\/\/bijoos.com\/oraclenotes\/2018\/2210\/","url_meta":{"origin":14,"position":1},"title":"Oracle Tidbits &#8211; July 2018 #oratidbit","author":"biju.thomas","date":"August 1, 2018","format":false,"excerpt":"\u201cOracle *daily* TidBits\u201d (#oratidbit) published on\u00a0\u00a0Facebook,\u00a0Twitter,\u00a0and\u00a0Google+\u00a0during weekdays\u00a0in July 2018. Hope you find these helpful to learn something new or to remind you of its existence and use. #oratidbit #db18c To change a regular user (password authenticated) to schema only account, the user should not have any administrative privileges (SYSDBA, SYSRAC,\u2026","rel":"","context":"In &quot;TidBits &amp; Quick Tips&quot;","block_context":{"text":"TidBits &amp; Quick Tips","link":"https:\/\/bijoos.com\/oraclenotes\/category\/tidbits\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/bijoos.com\/oraclenotes\/wp-content\/uploads\/2018\/04\/oratidbit.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":195,"url":"https:\/\/bijoos.com\/oraclenotes\/2013\/195\/","url_meta":{"origin":14,"position":2},"title":"A PL\/SQL Program &#8211; After many many years!","author":"Biju","date":"August 2, 2013","format":false,"excerpt":"Wrote a little pl\/sql program after several years... glad it worked as expected... thought of sharing the code, might be useful for someone out there... The requirement is to drop tables that are older than 60 days from a schema named CR_BKUP periodically. Did not want to just drop the\u2026","rel":"","context":"In &quot;Oracle Database&quot;","block_context":{"text":"Oracle Database","link":"https:\/\/bijoos.com\/oraclenotes\/category\/oracledb\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":1516,"url":"https:\/\/bijoos.com\/oraclenotes\/2015\/1516\/","url_meta":{"origin":14,"position":3},"title":"Preventing CREATE (only) for a User","author":"Biju","date":"April 27, 2015","format":false,"excerpt":"The PL\/SQL reference guide has a short section and example for the INSTEAD OF CREATE ON SCHEMA\u00a0trigger.\u00a0Since the description was so little and could not find much detail on the internet, tried some examples as below. This feature is good to prevent any CREATE operation for an user, giving him\/her\u2026","rel":"","context":"In &quot;Oracle Database&quot;","block_context":{"text":"Oracle Database","link":"https:\/\/bijoos.com\/oraclenotes\/category\/oracledb\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]},{"id":2197,"url":"https:\/\/bijoos.com\/oraclenotes\/2018\/2197\/","url_meta":{"origin":14,"position":4},"title":"Oracle Tidbits &#8211; June 2018 #oratidbit","author":"biju.thomas","date":"July 1, 2018","format":false,"excerpt":"\u201cOracle *daily* TidBits\u201d (#oratidbit) published on\u00a0\u00a0Facebook,\u00a0Twitter,\u00a0and\u00a0Google+\u00a0during weekdays\u00a0in June 2018. Hope you find these helpful to learn something new or to remind you of its existence and use. #oratidbit #db18c A shared single client access name (Shared SCAN) enables the sharing of one set of SCAN virtual IPs (VIPs) and Listeners\u2026","rel":"","context":"In &quot;TidBits &amp; Quick Tips&quot;","block_context":{"text":"TidBits &amp; Quick Tips","link":"https:\/\/bijoos.com\/oraclenotes\/category\/tidbits\/"},"img":{"alt_text":"","src":"https:\/\/i0.wp.com\/bijoos.com\/oraclenotes\/wp-content\/uploads\/2018\/04\/oratidbit.jpg?resize=350%2C200&ssl=1","width":350,"height":200},"classes":[]},{"id":1444,"url":"https:\/\/bijoos.com\/oraclenotes\/2014\/1444\/","url_meta":{"origin":14,"position":5},"title":"Oracle Tidbits &#8211; August 2014","author":"Biju","date":"September 1, 2014","format":false,"excerpt":"\u201cOracle *daily* TidBits\u201d published at\u00a0https:\/\/www.facebook.com\/oraclenotes\u00a0on all weekdays\u00a0in August\u00a02014. You will also see these tidbits, one tidbit at a time, for each page refresh on the right side of this blog as well\u2026 Hope you find these helpful to learn something new or to remind you of its existence and use...\u2026","rel":"","context":"In &quot;TidBits &amp; Quick Tips&quot;","block_context":{"text":"TidBits &amp; Quick Tips","link":"https:\/\/bijoos.com\/oraclenotes\/category\/tidbits\/"},"img":{"alt_text":"","src":"","width":0,"height":0},"classes":[]}],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/bijoos.com\/oraclenotes\/wp-json\/wp\/v2\/posts\/14","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/bijoos.com\/oraclenotes\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/bijoos.com\/oraclenotes\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/bijoos.com\/oraclenotes\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/bijoos.com\/oraclenotes\/wp-json\/wp\/v2\/comments?post=14"}],"version-history":[{"count":1,"href":"https:\/\/bijoos.com\/oraclenotes\/wp-json\/wp\/v2\/posts\/14\/revisions"}],"predecessor-version":[{"id":3002,"href":"https:\/\/bijoos.com\/oraclenotes\/wp-json\/wp\/v2\/posts\/14\/revisions\/3002"}],"wp:attachment":[{"href":"https:\/\/bijoos.com\/oraclenotes\/wp-json\/wp\/v2\/media?parent=14"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/bijoos.com\/oraclenotes\/wp-json\/wp\/v2\/categories?post=14"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/bijoos.com\/oraclenotes\/wp-json\/wp\/v2\/tags?post=14"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}