Home » SQL & PL/SQL » SQL & PL/SQL » triggers
triggers [message #38931] Tue, 28 May 2002 20:51 Go to next message
Australia
Messages: 4
Registered: May 2002
Junior Member
pseudocode for trigger:
trigger name:bfr_all_people_stmnt_tgr
event: insert, delete or update on people
timing and type: before statement
action:
if the day is not a working day ie monday to friday, then raise error -20020
else if the time is between 1:00am and 1:30am (inclusive) then
raise error -20020
end if
----------
/*my trigger*/CREATE or replace TRIGGER bfr_all_people_stmnt_tgr
before insert or delete or update on people
DECLARE
day_num number; /*days of the week.*/
day_time number; /*time of day.*/
BEGIN
day_num = to_number (to.char(sysdate,'d'));
day_time = to_number (to.char(sysdate, 'HH:MI:SS'));
IF(day_num = 1) or (day_num = 7)) then
raise_application_error
(-20020, 'Not permitted at this time');
ELSIF((day_time >= 01:00:00) && (day_time <= 01:30:00)) then
raise_application_error
(-20020, 'Not permitted at this time');
END IF;
END;

/*can you please tell me if this is right, becasue i was unsure as how to do the between times 1:00am and 1:30am. I dont think this is right, so can someone please tell me how exactly its done? thanx */
Re: triggers [message #38932 is a reply to message #38931] Tue, 28 May 2002 20:53 Go to previous messageGo to next message
SiXey
Messages: 8
Registered: May 2002
Junior Member
sorry i misspelt my email address. it is ayesh66false@hotmail.com
Re: triggers [message #38935 is a reply to message #38931] Tue, 28 May 2002 22:16 Go to previous message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
create or replace trigger bfr_all_people_stmnt_tgr
before insert or delete or update on people
begin
  if to_char(sysdate, 'd') in ('1', '7') then
    raise_application_error(-20020, 'Not permitted at this time');
  elsif to_char(sysdate, 'hh24:mi:ss') between '01:00:00' and '01:30:00' then
    raise_application_error(-20020, 'Not permitted at this time');
  end if;
end;
/
Previous Topic: creating column heading as a literal string
Next Topic: Error handling and procedures
Goto Forum:
  


Current Time: Tue May 21 17:31:24 CDT 2024