【发布时间】:2020-03-06 22:24:52
【问题描述】:
我是一名 DBA,只是想编写一段代码来捕获 Oracle 中的用户权限并写入表。下面的代码适用于一个用户,但如果 ELSE 部分有多个用户,我会收到错误:“ORA-01422:精确提取返回的行数超过了请求的行数”。有道理,我意识到我需要一个 for/while 循环来处理多行,有人可以帮我吗?
'''
declare
altersystem varchar2(550);
altersystemconcat varchar2(550);
begin
select grantee
into altersystem
from dba_sys_privs
where privilege = 'ALTER SYSTEM'
and grantee not in ('SYS', 'SYSTEM');
if altersystem = 'No rows selected'
then
insert into catch
values
('900'
,'No custom users with the Alter System privilege.');
else
select concat('The following user/role has the Alter System privilege, revoke if not required: '
,altersystem)
into altersystemconcat
from dual;
insert into catch
values
('100'
,altersystemconcat);
end if;
end;
/
'''
【问题讨论】: