Results 1 to 2 of 2
  1. #1
    Join Date
    Mar 2004
    Posts
    3

    Unanswered: Current Time Automatically Entered

    Hi all

    I have created a table in Oracle that has a field called CURRENT_TIME. I am wondering if, for every time a record is entered into this table, can this field be automatically updated with the current system time without any human interaction if you know what I mean.
    Cheers

  2. #2
    Join Date
    Sep 2002
    Location
    UK
    Posts
    5,171
    Provided Answers: 1

    Re: Current Time Automatically Entered

    Yes, there are 2 ways:

    1) Default value:

    create table t (current_time date default sysdate, ...

    However, this allows the user to override like this:

    insert into t (current_time, ... ) values (sysdate-100, ... );

    2) Trigger:

    create or replace trigger t1 before insert on t
    for each row
    begin
    :new.current_time := sysdate;
    end;
    /

    This way, even if the user specifies a value for current_time, it will be overwritten by the trigger.

Posting Permissions

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