Solved

Trigger working with time & date

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

Any example ?
0
Comment
Question by:egovernment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
6 Comments
 
LVL 16

Expert Comment

by:Milleniumaire
ID: 37772310
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
ID: 37772316
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 74

Expert Comment

by:sdstuber
ID: 37772320
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
ID: 37773235
0
 
LVL 74

Accepted Solution

by:
sdstuber earned 500 total points
ID: 37774839
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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This post looks at MongoDB and MySQL, and covers high-level MongoDB strengths, weaknesses, features, and uses from the perspective of an SQL user.
Your data is at risk. Probably more today that at any other time in history. There are simply more people with more access to the Web with bad intentions.
This video explains what a user managed backup is and shows how to take one, providing a couple of simple example scripts.
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

688 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