Having run a grant
command in an Oracle SQL script, is there any way to tell if it actually changed anything. Like an equivalent of SQL%ROWCOUNT
or similar?
I am writing an ansible module which will manage grants (using SQLPlus internally to run the commands). It would be nice to be able to accurately report if it changed anything or if it was OK already. I guess I could do a bunch of selects first, but then I have to map each grant (there are different types of grants involved, including grants from sys to schema owner) to a select.
What I'd like to be able to do is something like
declare
vNum number := 0;
procedure do_grant(vGrant in varchar2) is
begin
execute immediate 'grant ' || vGrant || ' to myrole';
if SQL%CHANGED > 0 then
vNum := vNum + 1;
end if;
end do_grant;
begin
do_grant('select on foo');
do_grant('select on bar');
do_grant('execute on baz');
dbms_output(vNum);
end;
/
(This is simplified pseudocode, without error handling, etc. for simplicity, but I capture the output and update the status to ansible based on that.)