oracle 如何在星期六和星期日使用触发器限制模式

r7s23pms  于 2023-05-16  发布在  Oracle
关注(0)|答案(2)|浏览(159)
create or replace trigger login
after LOGON ON DATABASE

begin

    if to_char(sysdate,'dy')in ('sat','san') then
    raise_application_error(-20123,' we cant logon the database ');   
    end if;

end;
7xzttuei

7xzttuei1#

使用sys用户编译它..样本触发:

CREATE OR REPLACE TRIGGER login_trg
AFTER LOGON ON DATABASE
DECLARE

BEGIN
   IF to_char(SYSDATE,'D') NOT IN ('6','7') THEN
      raise_application_error(-20123,' we cant logon the database ');   
   END IF;
END;
rhfm7lfc

rhfm7lfc2#

你确定这是英语资料库吗?您可以在TO_CHAR中硬编码该语言,而无需更改系统或会话NLS参数。这可能比记住Oracle周是从1还是0开始,或者在您的特定区域设置中是从星期日还是星期一开始更好。
(今天是星期二,我正在测试这个。

SQL> ALTER SESSION SET NLS_DATE_LANGUAGE = 'ENGLISH';

Session altered.

SQL> SELECT TO_CHAR(SYSDATE, 'dy') FROM DUAL;

TO_CHAR(SYSD
------------
tue

SQL> ALTER SESSION SET NLS_DATE_LANGUAGE = 'SPANISH';

Session altered.

SQL> SELECT TO_CHAR(SYSDATE, 'dy') FROM DUAL;

TO_CHAR(SYSD
------------
mar

SQL> -- This will work even though our session is still in Spanish.
SQL> SELECT TO_CHAR(SYSDATE, 'dy', 'NLS_DATE_LANGUAGE=''ENGLISH''') FROM DUAL;

TO_CHAR(SYSD
------------
tue

SQL>

相关问题