ORA-01422与ORA-01403错误

添加一个'AFTER LOGON ON DATABASE'的trigger以后,发现日志中出现如下错误片段:

ORA-00604: 递归 SQL 级别 1 出现错误
ORA-01422: 实际返回的行数超出请求的行数
ORA-06512: 在 line 5

检查了trigger中的查询语句后,发现以下查询的确是返回了多行数据:

select username,SYS_CONTEXT('USERENV','IP_ADDRESS')  
into v_username,v_ip
from sys.v_$session where AUDSID = SYS_CONTEXT('USERENV', 'SESSIONID');

在后面加入了过滤条件,完整语句如下:

select username,SYS_CONTEXT('USERENV','IP_ADDRESS')  
into v_username,v_ip
from sys.v_$session where AUDSID = SYS_CONTEXT('USERENV', 'SESSIONID')
 and upper(username) not in ('SYS') and type<>'BACKGROUND';

解决此问题后,发现报了另外一个错误:

ORA-04088: error during execution of trigger '...'
ORA-01403: no data found
ORA-06512: at line 5

加入如下异常处理语句后解决:

EXCEPTION
 WHEN NO_DATA_FOUND
  THEN
...

 

你可能感兴趣的:(ORA-01422与ORA-01403错误)