需求:只允许一些用户在特定时间内登录
实现方式:通过触发器去实现(对具有dba权限的用户不适用),触发器代码如下
CREATE OR REPLACE TRIGGER limit_connection
AFTER LOGON ON DATABASE
BEGIN
IF USER = 'USERNAME' THEN
IF to_number(TO_CHAR (SYSDATE, 'hh24')) BETWEEN 20 AND 24
THEN
RAISE_APPLICATION_ERROR(-20998,' Dear user '||USER||'! You can''t login between 20 and 24');
END IF;
END IF;
END limit_connection;
/
测试登录,会正常拒绝登录
ERROR:
ORA-00604: error occurred at recursive SQL level 1
ORA-20998: Dear user OE! You can't login between 00 and 08
ORA-06512: at line 5
reference