限制用户只能在特定时间段登录 oracle

需求:只允许一些用户在特定时间内登录

实现方式:通过触发器去实现(对具有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

感谢&参考https://blog.csdn.net/weixin_39783426/article/details/116351855

posted @ 2022-11-15 23:06  wazz_s  阅读(73)  评论(0编辑  收藏  举报