Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 5746
  • Last Modified:

how to grant select privilege on all sequences within the schema

Hi,
 I have around 30 sequences within a schema say schema_xyz. I would like to give select privilege on all the sequences. What is the best way or command to do it. Any links, resources, sample code, ideas highly appreciated. Thanks in advance.
0
gudii9
Asked:
gudii9
3 Solutions
 
Raja Jegan RSQL Server DBA & ArchitectCommented:
You can select All Sequences available using the below query

SELECT 'GRANT SELECT ON ' || SCHEMA || '.' || sequencename || 'TO hr;' as grant_stmt
FROM ALL_CATALOG
WHERE TABLE_TYPE = 'SEQUENCE'

Once you have the list, you can execute the dynamic sql statements in a cursor loop for all Sequences.
0
 
MilleniumaireCommented:
Create the following script and call it grant.sql

set heading off pagesize 0 feedback off
spool grantscript.sql

select 'grant select on '||sequence_owner||'.'||sequence_name||' to xyz;'
from all_sequences
where sequence_owner = 'MYUSER;

spool off
@grantscript.sql

exit;

Run the above from sqlplus as follows:

sqlplus username/password @grant

Obviously you will need to change MYUSER and xyz as appropriate.
0
 
johnsoneSenior Oracle DBACommented:
This should work as well.

You need to replace schema_abc with the schema you want to grant the privileges to.
begin
  for c1rec in (select 'grant select on ' || sequence_owner || '.' || sequence_name || ' to schema_abc' stmt from dba_sequences where sequence_owner = 'SCHEMA_XYZ') loop
    execute immediate c1rec.stmt;
  end loop;
end;
/

Open in new window

0
 
gudii9Author Commented:
thank you
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now