我正在做以下问题
Managing Locked Accounts – The utility should be able to identify each locked
account that was locked because of invalid login attempts. The utility should further
unlock accounts that have been locked for more than a week.
----------------------------------------我的代码----- -------------------------------------
procedure Managing_Locked
is
num int;
V_SQL varchar(50);
begin
for x in (select USERNAME,LOCK_DATE,ACCOUNT_STATUS,PROFILE from DBA_USERS where ACCOUNT_STATUS ='LOCKED(TIMED)')
loop
dbms_output.put_line('USERNAME: '|| x.USERNAME);
dbms_output.put_line('LOCK_DATE: '|| x.LOCK_DATE );
dbms_output.put_line('ACCOUNT_STATUS: '||x.ACCOUNT_STATUS);
dbms_output.put_line('PROFILE: ' ||x.PROFILE);
dbms_output.put_line('*********************');
select ((sysdate - x.LOCK_DATE)) into num from dual;
if(num>7)
then
V_SQL := 'ALTER USER'|| x.USERNAME ||'ACCOUNT UNLOCK';
dbms_output.put_line(x.USERNAME||' UNLOCK');
Execute immediate(V_SQL);
end if;
end loop;
end;
错误00940. 00000 - “ALTER命令无效”
我收到了这个错误,我没有看到alter命令
有什么问题答案 0 :(得分:0)
在单词account之前添加一个空格。
“account”一词缺少用户名,因此您发出的命令是“alter user usernameaccount unlock”...
答案 1 :(得分:0)
为了捕捉每个可能的状态,where子句应该是这个:
WHERE ACCOUNT_STATUS IN (
'LOCKED(TIMED)',
'EXPIRED & LOCKED(TIMED)',
'EXPIRED(GRACE) & LOCKED(TIMED)')
或
WHERE ACCOUNT_STATUS LIKE '%LOCKED(TIMED)'