How to grant privileges on all the tables in a schema

Hi All,
Can you tell me how to grant privileges on all the tables of a schema A
to schema B.
For Example:
There are 200 tables in schema A, I wanted to grant select privilege on all the tables of a scheme A to schema B.
Thanks in advance.

note that USER is the user that will have the select priviledge
the procedure includes views as well
CREATE OR REPLACE PROCEDURE GRANT_ACCESS_ON_USER IS
CURSOR c1 is select table_name from user_tables;
CURSOR c2 is select view_name from user_views;
tablename user_tables.TABLE_NAME%TYPE;
viewname user_views.VIEW_NAME%TYPE;
BEGIN
tmpVar := 0;
OPEN c1;
loop
     fetch c1 into tablename;
     EXIT WHEN c1%NOTFOUND;
     EXECUTE IMMEDIATE 'GRANT SELECT on '||tablename ||' to USER';
end loop ;
close c1;
OPEN c2;
loop
     fetch c2 into viewname;
     EXIT WHEN c2%NOTFOUND;
     EXECUTE IMMEDIATE 'GRANT SELECT on '||viewname ||' to USER';
end loop ;
close c2;
EXCEPTION
WHEN NO_DATA_FOUND THEN
NULL;
WHEN OTHERS THEN
-- Consider logging the error and then re-raise
RAISE;
END;
/

Similar Messages

  • ORACLE - How to GRANT privilegies on ALL the tables belonging to a schema

    Is there a way to grant to a user the same privilegies on ALL the tables belonging to the same schema, so that, in case a new table is created afterwards, the grant is automatically given ?
    Thanks in adance for any reply

    Yes of course ! Just do the same as Oracle Applications: an end user has no Oracle account, the application code connects with the Oracle account that is the schema owner:
    no more grant needed ... That's a joke but it's also true ! In this case, your application must implement its own security (password management, audit, privileges) and you will not be able to use Oracle privileges, auditing and advanced security features ... just like Oracle Applications.
    The above answers are of course correct. You can also create an Oracle role that you can grant to the Oracle users and grant the privileges to this role everytime a new table is created to avoid granting privileges for each new object to each user.

  • How to GRANT SELECT on all the tables in 1 go?

    Hi
    I have many tables (close to 200) in my Schema. I want to grant SELECT ON ALL TABLES to another user. How do I achieve this in one go?
    Thanking you in advance,
    ...

    Although Justin has given a wonderful answer. You might also review the following threads;
    Grant select on a schema
    Re: Grant select on a schema
    grant select on
    grant select  on
    grant select on tables
    Re: grant select on tables
    Adith

  • How to find accurate number of Rows, and size of all the tables of a Schema

    HI,
    How to find the accurate number of Rows, and size of all the tables of a Schema ????
    Thanks.

    SELECT t.table_name AS "Table Name",
    t.num_rows AS "Rows",
    t.avg_row_len AS "Avg Row Len",
    Trunc((t.blocks * p.value)/1024) AS "Size KB",
    t.last_analyzed AS "Last Analyzed"
    FROM dba_tables t,
    v$parameter p
    WHERE t.owner = Decode(Upper('&1'), 'ALL', t.owner, Upper('&1'))
    AND p.name = 'db_block_size'
    ORDER by 4 desc nulls last;
    ## Gather schema stats
    begin
    dbms_stats.gather_schema_stats(ownname=>'SYSLOG');
    end;
    ## Gather a particular table stats of a schema
    begin
    DBMS_STATS.gather_table_stats(ownname=>'syslog',tabname=>'logs');
    end;
    http://www.oradev.com/create_statistics.jsp
    Hope this will work.
    Regards
    Asif Kabir
    -- Mark the answer as correct/helpful

  • How to fetch what are all the tables used in this TR no and Package name of

    Hi Friends,
    I have input of Transport Request no (E070-TRKORR).
    How to fetch what are all the tables used in this TR no and Package name of this Table.

    HI,
    FYI
    SELECT E071OBJECT_NAME, E070MDEVCLASS
    FROM E071, E070M
    WHERE TRKORR = YOU REQUEST NO.

  • Grant access to all object/tables in other schemas to a user

    Is there any and simple way to grant access to all object/tables in other schemas (more than one) to a scheme/user?
    Thanks.
    Tarman.

    HI.
    grant SELECT ANY TABLE,delete any table, insert any table to user; Giving this delete,insert ANY TABLE privilege to a user can be dangerous and the use can mislead it. Its better to create a dynamic script and then grant it.
    E.g Suppose you want to give select,inert,delete,update privileges to user A on user B's object.
    sql> spool grants.sql
    sql> select 'grant select,insert,update,delete on '||owner||'.'||table_name||' to A;' from dba_tables where owner='B';
    sql>@grants.sqlHTH
    Anand

  • How to find out all the tables in a schema with a particular column

    Hi
    Is there a way to find out all the tables in schema1 that has col1 as one of the columns?

    select table_name from dba_tab_cols where owner='schema' and column_name='col1';

  • How to move all the tables from one tablespace to other for a whole schema

    Hi,
    Is there any way to move all the tables in a schema from one tablespace to other?
    If so please help me out to do that.
    Thanks
    Regards
    Gatha

    hi,
    here is the steps to move SCOTT's objects from their current tablespace to a NEW_TABLESPACE
    would be:
    1) do an export of all of scott's objects. Make sure no one modifies them after you
    begin this process. You will lose these changes if they do.
    $ exp userid=scott/tiger owner=scott
    2) you would drop all of scotts tables. This will get the indexes as well. I don't
    suggest dropping the user SCOTT but rather dropping scott's objects. Dropping scott
    would cause any system priveleges SCOTT has to disappear and the import would not restore
    them. This script can be used to drop someones tables:
    set heading off
    set feedback off
    set verify off
    set echo off
    spool tmp.sql
    select 'drop table &1..' || table_name || ' cascade constraints;'
    from dba_tables
    where owner = upper('&1')
    spool off
    @tmp.sql
    3) You would modify the user to not have unlimited tablespace (else the IMP will just
    put the objects right back into the tablespace they came from) and then give them
    unlimited quota's on the new tablespace you want the objects to go into and on their
    temporary tablespace (for the sorts the index creates will do)
    alter user SCOTT default tablespace NEW_TABLESPACE
    revoke unlimited tablespace from SCOTT
    alter user SCOTT quota unlimited on NEW_TABLESPACE
    alter user SCOTT quota unlimited on SCOTTS_TEMPORARY_TABLESPACE
    4) you will IMP the data back in for that user. IMP will rewrite the create statements
    to use the users default tablespace when it discovers that it cannot create the objects
    in their original tablespace. Please make sure to review the file imp.log after you do
    this for any and all errors after you import.
    imp userid=scott/tiger full=y ignore=y log=imp.log
    5) you can optionally restore 'unlimited tablespace' to this user (or not). If you do
    not, this user can only create objects in this new tablespace and temp (which in itself
    is not a bad thing)...
    Regards,
    Mohd Mehraj Hussain
    http://mehrajdba.wordpress.com

  • Grant access to all the views created in user schema to another schema

    How to grant access for all the views created in own HAGGIS schema to comqdhb schema on the HAGGIS database.
    Oracle Grant Privileges
    ===============
    Object privileges assign the right to perform a particular operation on a specific object
    I read that we can use select 'grant select on' ||view_name||'HAGGIS' user_views where owner='COMQDHB'
    Is this right
    Oracle System Privileges
    ===============
    System privileges should be used in only cases where security isnt important,because a single grant statement could remove all security from the table
    Role based security
    ============
    Role security allows you to gather related grants into a collection-since the role is a predefined collection of privileges that are grouped together.privileges are easier to assign to users.
    [http://www.dba-oracle.com/art_builder_grant_sec.htm]
    can we grant select update to all the views at a time to the other schema.
    Are there any other ways to secure the data other than creating users and assigning roles.
    Thank you
    Edited by: Trooper on Dec 23, 2008 9:24 AM

    I think what was suggested was that you use SQL to generate the grants on each and every view, that is, you use SQL to generate SQL where the SQL being generated is "grant select on view_name to role'"
    If you users to connect to Oracle you have to create usernames for them though if the users only connect via an application the application might run just as one user and access to the application is controled via application security. The control on the application can be via Directory Services such as OID or MS Active Directory. User access to Oracle can also be controlled via OID.
    To connect to Oracle you can use OS authenication (not recommended), usernames with passwords, or via Advanced Security Option which supports single sign-on products like Kebros or Oracle Internet Directory etc....
    Example using SQL to generate SQL
    How do I find out which users have the rights, or privileges, to access a given object ?
    http://www.jlcomp.demon.co.uk/faq/privileges.html
    HTH -- Mark D Powell --

  • READ privileges for *all the databases*

    Is it possible to grant READ privileges for all the databases objects (tables, schema, triggers, procedures, view and etc)

    SHANOJ wrote:
    Is it possible to grant privileges to all objects in one time?It depends on what you mean by 'in one time'. In one single SQL statement? No. But there's nothing stopping you issuing a billion grants one after the other in your session.
    Roles are probably better suited for this task. But are you sure you really want to grant SELECT privileges on all the tables in the database? It's more common to grant SELECT on all the 'MARKAPP' tables to the 'MARKAPP_READ_ONLY' role...

  • Script for dropping all the tables

    Hello:
    Can somebody share with me a script that will delete all the tables in a schema?
    Thanks.

    I think what Justin was getting at is this: we cannot drop tables that are referenced by foreign keys. So before we can drop all tables weed to drop all referencing constraints. Which makes this script even more dangerous - you may wish to abort if other schemas reference the "droppee".
    Let's be careful out there!
    Cheers, APC
    declare
        cursor fks is
            select owner,table_name, constraint_name
            from all_constraints
            where r_owner='&&schema_to_delete'
            and constraint_type = 'R';
        cursor tables is
            select owner,table_name
            from all_tables
            where owner='&&schema_to_delete';
        begin
            for b in fks
            loop
                dbms_output.put_line( 'drop fk constraint '||b.owner||'.'||b.table_name||'.'||b.constraint_name);
                execute immediate 'alter table '||b.owner||'.'||b.table_name||' drop constraint '||b.constraint_name;
            end loop;
            for c in tables
            loop
                dbms_output.put_line( 'drop table '||c.owner||'.'||c.table_name);
                execute immediate 'drop table '||c.owner||'.'||c.table_name;
        end loop;
    end;
    /

  • How to find all the tables associated for a particular transaction

    Hi-
    May I know how to find all the tables, related(foreign key) tables for a transaction within SAP GUI?
    Up to my technical knowledge, this can be achieved by looking database diagrams from DB level. But that would be for entire database as a whole. What I'm expecting is to see transaction level relative tables that too from SAP GUI. Please share the possibilities if any.
    Regards
    Sekhar

    Dear Micky Oestreich
    May be we possess expertise or high level experience, it should not show up in our way of communication. Every professional starts with the basic stuff to learn. When the question is raised in such minimum polite way, the same level of courtesy is expected in return. If you felt my question was basic, you might have refused it gently. If you are in good mood or bad mood it doesn't matters.
    Hi Vengal Rao
    Thanks for your response. It helped me.
    Regards
    Sekhar

  • How will get the source code of all the tables in a given schema using SQL?

    Hi All,
    How can we get the source code of all the tables in a given schema using SQL?
    Thanks in Adv.
    Junu

    Try something like...
    set heading off
    set pagesize 0
    col meta_data for a96 word_wrapped
    set long 100000
    SELECT DBMS_METADATA.GET_DDL(object_type, object_name, owner) ||';' AS meta_data
    FROM dba_objects
    WHERE owner = '<SCHEMA NAME>'
      AND object_type not in (<list of stuff you do not want>);                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to generate test data for all the tables in oracle

    I am planning to use plsql to generate the test data in all the tables in schema, schema name is given as input parameters, min records in master table, min records in child table. data should be consistent in the columns which are used for constraints i.e. using same column value..
    planning to implement something like
    execute sp_schema_data_gen (schemaname, minrecinmstrtbl, minrecsforchildtable);
    schemaname = owner,
    minrecinmstrtbl= minimum records to insert into each parent table,
    minrecsforchildtable = minimum records to enter into each child table of a each master table;
    all_tables where owner= schemaname;
    all_tab_columns and all_constrains - where owner =schemaname;
    using dbms_random pkg.
    is anyone have better idea to do this.. is this functionality already there in oracle db?

    Ah, damorgan, data, test data, metadata and table-driven processes. Love the stuff!
    There are two approaches you can take with this. I'll mention both and then ask which
    one you think you would find most useful for your requirements.
    One approach I would call the generic bottom-up approach which is the one I think you
    are referring to.
    This system is a generic test data generator. It isn't designed to generate data for any
    particular existing table or application but is the general case solution.
    Building on damorgan's advice define the basic hierarchy: table collection, tables, data; so start at the data level.
    1. Identify/document the data types that you need to support. Start small (NUMBER, VARCHAR2, DATE) and add as you go along
    2. For each data type identify the functionality and attributes that you need. For instance for VARCHAR2
    a. min length - the minimum length to generate
    b. max length - the maximum length
    c. prefix - a prefix for the generated data; e.g. for an address field you might want a 'add1' prefix
    d. suffix - a suffix for the generated data; see prefix
    e. whether to generate NULLs
    3. For NUMBER you will probably want at least precision and scale but might want minimum and maximum values or even min/max precision,
    min/max scale.
    4. store the attribute combinations in Oracle tables
    5. build functionality for each data type that can create the range and type of data that you need. These functions should take parameters that can be used to control the attributes and the amount of data generated.
    6. At the table level you will need business rules that control how the different columns of the table relate to each other. For example, for ADDRESS information your business rule might be that ADDRESS1, CITY, STATE, ZIP are required and ADDRESS2 is optional.
    7. Add table-level processes, driven by the saved metadata, that can generate data at the record level by leveraging the data type functionality you have built previously.
    8. Then add the metadata, business rules and functionality to control the TABLE-TO-TABLE relationships; that is, the data model. You need the same DETPNO values in the SCOTT.EMP table that exist in the SCOTT.DEPT table.
    The second approach I have used more often. I would it call the top-down approach and I use
    it when test data is needed for an existing system. The main use case here is to avoid
    having to copy production data to QA, TEST or DEV environments.
    QA people want to test with data that they are familiar with: names, companies, code values.
    I've found they aren't often fond of random character strings for names of things.
    The second approach I use for mature systems where there is already plenty of data to choose from.
    It involves selecting subsets of data from each of the existing tables and saving that data in a
    set of test tables. This data can then be used for regression testing and for automated unit testing of
    existing functionality and functionality that is being developed.
    QA can use data they are already familiar with and can test the application (GUI?) interface on that
    data to see if they get the expected changes.
    For each table to be tested (e.g. DEPT) I create two test system tables. A BEFORE table and an EXPECTED table.
    1. DEPT_TEST_BEFORE
         This table has all EMP table columns and a TEST_CASE column.
         It holds EMP-image rows for each test case that show the row as it should look BEFORE the
         test for that test case is performed.
         CREATE TABLE DEPT_TEST_BEFORE
         TESTCASE NUMBER,
         DEPTNO NUMBER(2),
         DNAME VARCHAR2(14 BYTE),
         LOC VARCHAR2(13 BYTE)
    2. DEPT_TEST_EXPECTED
         This table also has all EMP table columns and a TEST_CASE column.
         It holds EMP-image rows for each test case that show the row as it should look AFTER the
         test for that test case is performed.
    Each of these tables are a mirror image of the actual application table with one new column
    added that contains a value representing the TESTCASE_NUMBER.
    To create test case #3 identify or create the DEPT records you want to use for test case #3.
    Insert these records into DEPT_TEST_BEFORE:
         INSERT INTO DEPT_TEST_BEFORE
         SELECT 3, D.* FROM DEPT D where DEPNO = 20
    Insert records for test case #3 into DEPT_TEST_EXPECTED that show the rows as they should
    look after test #3 is run. For example, if test #3 creates one new record add all the
    records fro the BEFORE data set and add a new one for the new record.
    When you want to run TESTCASE_ONE the process is basically (ignore for this illustration that
    there is a foreign key betwee DEPT and EMP):
    1. delete the records from SCOTT.DEPT that correspond to test case #3 DEPT records.
              DELETE FROM DEPT
              WHERE DEPTNO IN (SELECT DEPTNO FROM DEPT_TEST_BEFORE WHERE TESTCASE = 3);
    2. insert the test data set records for SCOTT.DEPT for test case #3.
              INSERT INTO DEPT
              SELECT DEPTNO, DNAME, LOC FROM DEPT_TEST_BEFORE WHERE TESTCASE = 3;
    3 perform the test.
    4. compare the actual results with the expected results.
         This is done by a function that compares the records in DEPT with the records
         in DEPT_TEST_EXPECTED for test #3.
         I usually store these results in yet another table or just report them out.
    5. Report out the differences.
    This second approach uses data the users (QA) are already familiar with, is scaleable and
    is easy to add new data that meets business requirements.
    It is also easy to automatically generate the necessary tables and test setup/breakdown
    using a table-driven metadata approach. Adding a new test table is as easy as calling
    a stored procedure; the procedure can generate the DDL or create the actual tables needed
    for the BEFORE and AFTER snapshots.
    The main disadvantage is that existing data will almost never cover the corner cases.
    But you can add data for these. By corner cases I mean data that defines the limits
    for a data type: a VARCHAR2(30) name field should have at least one test record that
    has a name that is 30 characters long.
    Which of these approaches makes the most sense for you?

  • How to see all the tables in ABAP

    how to see all the tables in ABAP
    i need to see all the tables present in tcode se16.

    Hi Thiru ,
    its tough to give all.so pls see the below links u can get all.
    http://www.erpgenie.com/abap/tables.htm
    https://www.sdn.sap.com/irj/sdn/advancedsearch?query=listofalltablesin+abap&cat=sdn_all
    http://www.guidancetech.com/people/holland/sap/abap/
    http://www.sap-img.com/ab017.htm
    http://abap-gallery.blogspot.com/
    thanks
    karthik

Maybe you are looking for

  • ITunes for the family

    My situation is that my son, now 12, has his own iPhone and has been purchasing his games, apps and music on my itunes account.  Am I able to transfer all his purchases to his new itunes account or is all his data and game progress gone?

  • Can't Connect Properly to Router After Successful Airport Express Setup

    Hello - this is my first time posting here, but I had a weird issue I was hopeful someone could assist with. Basically, I was having a lot of trouble setting up my Airport Express to join my existing network to steam audio to a set of speakers. After

  • How can I use this code in Muse?

    Please, tell me with details how to paste this code, which the "add this" widget on Muse to appear... <!-- AddThis Smart Layers BEGIN --> <!-- Go to http://www.addthis.com/get/smart-layers to customize --> <script type="text/javascript" src="//s7.add

  • Newbee question - will this work?

    I want to use RoboHelp to create a winhelp version for a desktop application and a webhelp version that will contain more up-to-date information as material is added/expanded. Perhaps downloading new winhelp versions to upgrade the desktop help. It l

  • Need to disable Proxies...

    My internet satellite provider just did a repoint & modem reconfiguration on my system and I can't get into Safari at all (fails to load page). I called my provider and was told that i needed to disable my proxies. When i go into system preferences.n