I like to generate the scripts of grant
at hand, because we usually perform once, through a query
:
SELECT 'GRANT select,update,delete,insert ON ' || x.table_name || ' TO STACKOVERFLOW;'
FROM all_tables x
WHERE x.owner = USER;
Then the result I copy and execute.
Or the same case using BULK COLLECT, when we have a large volume of tables:
DECLARE
TYPE t_cursor IS REF CURSOR;
TYPE t_string_array IS TABLE OF VARCHAR2(1000) INDEX BY BINARY_INTEGER;
vcursor t_cursor;
varraystring t_string_array;
i BINARY_INTEGER;
BEGIN
OPEN vcursor FOR
SELECT 'GRANT select,update,delete,insert ' || x.table_name || ' TO STACKOVERFLOW'
FROM all_tables x
WHERE x.owner = USER;
LOOP
FETCH vcursor BULK COLLECT
INTO varraystring;
EXIT WHEN varraystring.count = 0;
FOR i IN varraystring.first .. varraystring.last LOOP
EXECUTE IMMEDIATE varraystring(i);
END LOOP;
EXIT WHEN vcursor%NOTFOUND;
END LOOP;
CLOSE vcursor;
END;
There are other more complex ways to do it, but I believe this one solves your case.
Excuse the question, but when I run the code above, changing to my real parameters, giving syntax error, I need to pay attention to some conditional ?
– Diogo dgo
Maybe you need the
BEGIN
andEND;
respectively at the beginning and at the end if the script is not recognized. If it works I update the response :)– Zulian