Solved

Trigger working with time & date

Posted on 2012-03-27
6
484 Views
Last Modified: 2012-06-27
How can Triggers working with Time & Date ?

Any example ?
0
Comment
Question by:egovernment
6 Comments
 
LVL 16

Expert Comment

by:Milleniumaire
Comment Utility
Can you provide more information about what you are trying to do?  What do you mean by "working with Time & Date"?
0
 
LVL 23

Expert Comment

by:David
Comment Utility
Would you rephrase your question, or provide a specific example?  Triggers can be used with data manipulation statements (DML), so the standard datatype syntax applies with the TO_DATE function, for example.  If you need a column value to change, say, to the current SYSDATE, I would use something like UPDATE tab1 SET col1 = SYSDATE WHERE ....
0
 
LVL 73

Expert Comment

by:sdstuber
Comment Utility
here's a simple example of a trigger that captures the current system time on insert and assigns it to one of the columns in my table

is this what you were looking for?

CREATE OR REPLACE TRIGGER my_trigger
BEFORE INSERT ON my_table
FOR EACH ROW
BEGIN
   :new.my_date_column := SYSDATE;
END;
/
0
 
LVL 16

Expert Comment

by:Wasim Akram Shaik
Comment Utility
0
 
LVL 73

Accepted Solution

by:
sdstuber earned 500 total points
Comment Utility
the trigger itself can't be time based.

however, you can put time controls within the trigger so that if it fires outside the appropriate time window it doesn't do anything.


CREATE OR REPLACE TRIGGER my_trigger
BEFORE INSERT ON my_table
FOR EACH ROW
BEGIN
   if sysdate > trunc(sysdate)+16/24 then
          dbms_output.put_line('It is after 4pm');  -- put other code here
   elsif sysdate > to_date('2012-04-01','yyyy-mm-dd') then
          dbms_output.put_line('It is after April 1, 2012'); -- put other code here
   else
          null; -- do nothing
   end if;
END;
/
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Read about achieving the basic levels of HRIS security in the workplace.
Although it can be difficult to imagine, someday your child will have a career of his or her own. He or she will likely start a family, buy a home and start having their own children. So, while being a kid is still extremely important, it’s also …
This video shows setup options and the basic steps and syntax for duplicating (cloning) a database from one instance to another. Examples are given for duplicating to the same machine and to different machines
Via a live example, show how to take different types of Oracle backups using RMAN.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now