Skip to content

Instantly share code, notes, and snippets.

@joshbode
Created August 16, 2013 22:19
Show Gist options
  • Select an option

  • Save joshbode/6253980 to your computer and use it in GitHub Desktop.

Select an option

Save joshbode/6253980 to your computer and use it in GitHub Desktop.
Grant access to multiple people working on a project to tables with names matching a particular pattern.
-- grant access to multiple people
DECLARE
usernames VARCHAR2(1024) := '
jimmy,
bobby,
franky,
alice,
mandy
';
table_filter VARCHAR2(128) := 'foo|bar';
BEGIN
FOR r IN (
SELECT LOWER(t.table_name) table_name
FROM user_tables t
WHERE REGEXP_LIKE(t.table_name, '^(' || table_filter || '_)')
) LOOP
EXECUTE IMMEDIATE 'GRANT SELECT ON ' || r.table_name || ' TO ' || usernames;
END LOOP;
END;
/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment