Results 1 to 3 of 3
  1. #1
    Join Date
    Dec 2003
    Posts
    148

    Unanswered: Trigger & timestamp

    Hi all...Is there a way I can have a column on a table get stamped with the current time (date not necessary as it is in another column) with the tmie everytime the table is inserted into?

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1
    Well, Oracle doesn't have a datatype for "time" divorced from "date". So you have to choose whether to store as DATE, VARCHAR2 or NUMBER. Why not just include a time component in your existing DATE column?

    Whatever you choose to do the trigger is simply:
    Code:
    create or replace trigger mytrg
    before insert on mytab
    for each row
    begin
      :new.timecol := ???;
    end;
    Substitute one of the following for ???:
    1) SYSDATE -- for a DATE column
    2) TO_CHAR(SYSDATE,'HH24:MIS') -- for a VARCHAR2 column
    3) TO_NUMBER(TO_CHAR(SYSDATE,'HH24MISS')) -- for a NUMBER column
    4) something else of your choice based on SYSDATE

  3. #3
    Join Date
    Dec 2003
    Posts
    148
    works great, thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •