I have 3 tables table1,table2,table3. I want to grant(select for example) these tables to a user, user1.
I know that I can grant with:
grant select
You can do it with dynamic query, just run the following script in pl-sql or sqlplus:
select 'grant select on user_name_owner.'||table_name|| 'to user_name1 ;' from dba_tables t where t.owner='user_name_owner'
and then execute result.
This worked for me on my Oracle database:
SELECT 'GRANT SELECT, insert, update, delete ON mySchema.' || TABLE_NAME || ' to myUser;'
FROM user_tables
where table_name like 'myTblPrefix%'
Then, copy the results, paste them into your editor, then run them like a script.
You could also write a script and use "Execute Immediate" to run the generated SQL if you don't want the extra copy/paste steps.
No. As the documentation shows, you can only grant access to one object at a time.
If you want to grant to both tables and views try:
SELECT DISTINCT
|| OWNER
|| '.'
|| TABLE_NAME
|| ' to db_user;'
FROM
ALL_TAB_COLS
WHERE
TABLE_NAME LIKE 'TABLE_NAME_%';
For just views try:
SELECT
'grant select on '
|| OWNER
|| '.'
|| VIEW_NAME
|| ' to REPORT_DW;'
FROM
ALL_VIEWS
WHERE
VIEW_NAME LIKE 'VIEW_NAME_%';
Copy results and execute.
my suggestion is...create role in oracle using
create role <role_name>;
then assign privileges to that role using
grant select on <table_name> to <role_name>;
then assign that group of privileges via that role to any user by using
grant <role_name> to <user_name>...;