Grant select on all table of a schema to role

Hi , is it possible to grant select on all table on a schema to a role?

To grant SELECT on all tables of the current schema to particular role or user:
SELECT 'GRANT SELECT ON '||TABLE_NAME||' TO READ_ONLY_ROLE;' COMMAND
FROM (
SELECT TABLE_NAME
FROM ALL_TABLES
WHERE OWNER = (SELECT USER FROM DUAL)
Then copy and execute the result commands, eg:
GRANT SELECT ON DEPT TO READ_ONLY_ROLE;
GRANT SELECT ON EMP TO READ_ONLY_ROLE;
GRANT SELECT ON DEMO_USERS TO READ_ONLY_ROLE;
GRANT SELECT ON DEMO_CUSTOMERS TO READ_ONLY_ROLE;
GRANT SELECT ON DEMO_ORDERS TO READ_ONLY_ROLE;

Similar Messages

  • Grant select on all tables of a schema

    I need to grant select on all tables (over 200 tables) of a schema to other users. Are there any SQL syntax to do this?
    Thanks!

    Execute the following script, modify it for your environment:
    Script
    Accept from_owner char prompt 'Grant from user:'
    Accept to_user char prompt 'grant to user:'
    set head off;
    set lines 300;
    set pages 0;
    set termout off;
    set feedback off;
    set head off;
    set verify off;
    spool d:\temp\grant.sql
    select 'grant select on &from_owner..'||
      table_name||
      ' to &to_user;'
      from dba_tables
      where owner=upper('&&from_owner');
    spool off;
    set head on;
    set pages 24;
    set termout on;
    set feedback on;
    set head on;
    @d:\temp\grant.sqlExecution example:
    system@DBA> @d:\temp\grants.sql
    Grant from user:scott
    grant to user:ejemplo
    Grant succeeded.
    Grant succeeded.
    Grant succeeded.
    Grant succeeded.
    Grant succeeded.
    Grant succeeded.
    Grant succeeded.

  • GRANT SELECT ON ALL TABLES

    Is there a direct SQL to grant select on all tables in the schema for a user? Or do we need to write a PLSQL for this?
    Also, if a new table T1 is created or existing table T2 is dropped and recreated after granting the select all privilege, will the user have access to T1 and T2?
    thanks

    Is there a direct SQL to grant select on all tables
    in the schema for a user? Or do we need to write a
    PLSQL for this?There is no privilege that would give user A access to all the tables in schema B. You would need to grant access to each object, which can certainly be done via dynamic SQL in PL/SQL.
    There is a privilege SELECT ANY TABLE which allows the user to query any table in the system, but this is generally very dangerous and probably not something you would want to give a normal user.
    Also, if a new table T1 is created or existing table
    T2 is dropped and recreated after granting the select
    all privilege, will the user have access to T1 and
    T2?Unless you grant SELECT ANY TABLE, you would need to explicitly grant A access to any new tables created in schema B (or to tables after they are dropped and re-created). Potentially, you could create a DDL trigger that submitted a job that would, in turn, make the grant whenever a new table was created in schema B.
    Justin

  • 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

  • Need to grant DML privileges to all tables in few schemas

    Hi,
    I need to grant DML privileges to all tables in few schemas to a role. How can I achieve that?
    I thought it's below syntax but it doesn't work. Please advice.
    grant ALL ON ALL TABLES IN SCHEMA <Schema_name>  TO <role_name>;Thanks,
    Gangadhar

    GR wrote:
    Hi,
    I need to grant DML privileges to all tables in few schemas to a role. How can I achieve that?
    I thought it's below syntax but it doesn't work. Please advice.
    grant ALL ON ALL TABLES IN SCHEMA <Schema_name>  TO <role_name>;
    There is no single command to grant privileges at that level. There are either ANY privileges or privileges on an object.
    You can write a bit of code to generate and execute what you want, but you would have to rerun it if any new tables were created.

  • Can we export DATA from all tables in a schema?

    Hi,
    I have a question; Can we export all the DATA from all the tables present in the schema to any source (eigther CSV, TXT, DAt, etc..)?
    Or
    Can I have a PL/SQL procedure to display DATA from all Tables in a schema?
    With Best Regards,
    - Naveed

    Hi,
    This is pretty much what you need.
    DECLARE
    V_COUNT NUMBER;
    v_sql varchar2(1000);
    IN_OWNER_NAME VARCHAR2(100) := 'AP' ; -- SCHEMA NAME
    TYPE T_COL_NAME is table of varchar2(1000) index by binary_integer;
    v_col_tbl t_col_name;
    BEGIN
    FOR i in
    (SELECT object_name
    FROM dba_objects
         WHERE owner = IN_OWNER_NAME
         AND object_type ='TABLE'
    and rownum < 2)
    LOOP
    v_sql := 'SELECT COUNT(*) FROM ' || i.object_name ;
    EXECUTE IMMEDIATE v_sql INTO V_COUNT;
    if v_count > 0 then
    v_sql := 'SELECT * FROM ' || i.object_name ;
    select column_name
    bulk collect
    into v_col_tbl
    from DBA_TAB_COLUMNS
    WHERE TABLE_NAME = I.OBJECT_NAME
    AND OWNER = IN_OWNER_NAME;
    -- start selecting the column and exporting using the column names selected.     
    end if;
    if v_col_tbl.count > 0 then
    for i in v_col_tbl.first .. v_col_tbl.last
    loop
    DBMS_OUTPUT.PUT_lINE(v_col_tbl(i));
    end loop;
    end if;
    DBMS_OUTPUT.PUT_lINE( i.object_name || '-' || v_count);
    END LOOP;
    END;
    - Ronel

  • Droping all tables in a schema

    how to drop all tables in a schema with out logging in that schema and having logged in as sys user?
    Thanks in advance
    Edited by: Prasanna.N on May 17, 2010 11:48 PM

    Prasanna.N wrote:
    Hi,
    i get this error
    ERROR at line 5:
    ORA-06550: line 5, column 9:
    PLS-00103: Encountered the symbol "end-of-file" when expecting one of the
    following:
    begin case declare end exception exit for goto if loop mod
    null pragma raise return select update while with
    <an identifier> <a double-quoted delimited-identifier>
    <a bind variable> << close current delete fetch lock insert
    open rollback savepoint set sql execute commit forall merge
    pipe
    when giving
    begin
    for t in (select table_name from dba_tables where owner = 'SCOTT')
    loop
    execute immediate 'drop table SCOTT.' || t.table_name || 'purge';
    end loop;
    /I just wrote for loop, of course you have to write inside begin..end block:
    begin
    for t in (select table_name from dba_tables where owner = 'SCOTT')
    loop
    execute immediate 'drop table SCOTT.' || t.table_name || '  purge';
    end loop;
    end;
    /

  • Program (PL/SQL) for count the registers of all tables in a schema

    Hi...
    I create a little program , for count the registers of all tables in the schema...
    If you need , send me your email...
    Atte
    Hector

    Hi,
    You can create a script by yourself by executing the script mentioned below:
    Connect as sys or system....
    SQL> spool test.sql
    SQL> select 'select count(*) from '||owner||'.'||table_name||';' from dba_tables;
    SQL> spool off;
    Hope this helps.
    Regards,
    -Praveen.
    http://myracle.wordpress.com

  • How to delete all rows in all tables of a schema in Oracle?

    Hi all,
    I want to delete all records of all tables of a schema and I think there should be some statement for this but I don't know how?
    may you help?
    Edited by: user8105261 on Nov 25, 2009 11:06 PM

    user8105261 wrote:
    Hi all,
    I want to delete all records of all tables of a schema and I think there should be some statement for this but I don't know how?
    may you help?
    Edited by: user8105261 on Nov 25, 2009 11:06 PMA typical way to reset a schema (e.g. to recreate a schema on the test database) is totally different.
    1) Drop the user
    2) recreate the user including table scripts from
    2a) your version control system
    2b) from a export dumpfile using the "nodata" option while importing

  • Can a procedure select data from tables on other schemas?

    Can a procedure select data from tables on other schemas?
    If it is posible, which syntax should I use to identify the tables and schemas on the SELECT query?

    Yes , it is possible..unless the current user has the right privileges on others' db objects schema.
    Now , as regards the syntax....
    1) The more descriptive way is to use the format ... <owner_schema>.<obj_name>.
    2) If you have declared public synonyms of other schema's objects then you can refer to them as just <obj.name>.... but the <owner_schema>.<obj_name> is not wrong.
    3) If the db objects reside on another database you must have declared a db link.... then the syntax is <owner_schema>.<obj_name>@<db_link_name>.
    Regards,
    Simon

  • Grant select on all of  views to public

    How to grant select on all of views to public? Thanks in advance.

    782150 wrote:
    How to grant select on all of views to public? Thanks in advance.
    spool doit.sql
    select 'grant select on '||
              owner ||
             '.' ||
             view_name ||
            ' to public;'
    from dba_views;
    spool offexecute doit.sql
    That's how it's done. Whether or not it's wise is a different question.

  • All columns of all table in one schema

    Hi
    All,
    Oralce 10.2.0.3
    I want to count all columns in all the table in one particular schema.
    How can I do that?
    which view i should use to count all cloumns of all tables in particular schema?
    Thanks

    vishal patel wrote:
    we needed for our data conversion project..I don't know how you'll use the number of columns in all a schema for data conversion. Some columns are duplicated (e.g. PK/FK), should they really count for two ?
    A data conversion means you should actually know what are the columns used for, not how many they are.
    one more question that count include hidden columns
    what is hidden column used for ? I can not see those columns in actual table.See here an example :
    Re: Difference btwn user_tab_cols & user_tab_columns
    Nicolas.

  • What privilege is needed to browse all tables in a schema

    I used SQLPlus to login to DB. When I clicked "table" in the left side window, no tables is shown. What privilege is needed to browse all tables in a schema?
    Thanks.

    SQL*Plus is a command-line interface. There is no side window to click on. Perhaps you're talking about SQL Programmer? Or are you talking about some other tool?
    What user are you logging in as? What user owns the objects? Do you just want to see that the tables exist? Or do you want to be able to see the data as well?
    Justin

  • Grant select only to all tables in certain schemas

    need to create an oracle database user with 'select only' right to all tables in schema OM + OE ( Order Management), Inventory(INV) and AR ( Account Receivables)

    apart from above suggestion dont forget to use to accomodate other schemas OM + OE ( Order Management), Inventory(INV) and AR ( Account Receivables);
    where a.owner in ('OM','OE','AR','INV');
    -- Raman.

  • Grant to all tables on my schema

    I am fairly new to Oracle and I need to grant "select, update, insert on all mytalbes to roleone, then grant that role to all my users.
    well, I have about 50 tables and 20 users.
    So far the most automated way I have come up with is:
    grant select, update, insert on table1 to role1;
    then I after that, I do:
    grant role1 to userone;
    I am sure there is a way to do this in some sort of procedure. I dont have DBA privs. I own all of the tables on my schema and those are the ones that I need to grant the privs to users.
    would you guys show me how to do this?
    thanks a bunch!

    You have to grant the privileges on each table to the role and then grant the role to each user, so you need 70 GRANT statements. You can write some dynamic SQL to generate the grants, though
    DECLARE
      sqlStmt VARCHAR2(4000);
    BEGIN
      FOR x IN (SELECT * FROM user_tables)
      LOOP
        sqlStmt := 'GRANT SELECT, UPDATE, INSERT ON ' || x.table_name || ' TO role1';
        EXECUTE IMMEDIATE sqlStmt;
      END LOOP;
    END;
    DECLARE
      sqlStmt VARCHAR2(4000);
    BEGIN
      FOR x IN (SELECT * FROM dba_users)
      LOOP
        sqlStmt := 'GRANT role1 TO ' || x.username;
        EXECUTE IMMEDIATE sqlStmt;
      END LOOP;
    END;Justin
    Distributed Database Consulting, Inc.
    http://www.ddbcinc.com/askDDBC

Maybe you are looking for

  • The application was unable to start correctly (0xc0150002). Click OK to close the application.

    The message above appears when I try to open After Effects and Premiere Pro. They were both downloaded today, alongside Photoshop which is working fine. I am a new Creative Cloud Member. I have tried restarting my computer but am completely unsure wh

  • Output determination ----Urgent

    Hi ,  I got a problem regarding Output determination in SD. There is credit memo , created based on an invoice. When iam taking the "Print preview " at the header level of the credit memo, " the Reference no./Date "   is not showing anything. When Ia

  • Scenarios without SUS

    Hi, I'm working with SRM 7.0 EhP2 and I want to configure the  supplier qualification scenario ( Registration, prescreening ecc..) and the function of POC (purchase order confirm). In my istallation is not expected PI and so I think is not possible t

  • Can the Calendar please be made to work

    Is it beyond Apple's ken to make a competent Calendar application? Is it not possible for the OS and the iPhone to understand and use floating time zones? I enter an appointment on the iPhone 2:30pm Eastern. I sync. I open Calendar on the Mac. In mon

  • I have had to go to a new computer, Have I lost all that I had bought?

    So I had a itunes set up and now have a new computer. Have I lost all the songs I bought on my old computer?