Time field creation [message #18550] |
Tue, 05 February 2002 05:45  |
Adebayo
Messages: 5 Registered: August 2001
|
Junior Member |
|
|
How do I create a field that records the time of data inputed into a data base.
for a similar example the date is done this way
CREATE TABLE DEV_SKILL (
DEV_ID NUMBER NOT NULL,
SKILL_ID NUMBER NOT NULL,
DATE_FILLED DATE NOT NULL)
how do I create the time field
|
|
|
|
Re: Time field creation [message #18554 is a reply to message #18550] |
Tue, 05 February 2002 07:05   |
Jon
Messages: 483 Registered: May 2001
|
Senior Member |
|
|
You missed Mike's point. Just create the field as date (time is implicit), as follows:
1 CREATE TABLE DEV_SKILL (
2 DEV_ID NUMBER NOT NULL,
3 SKILL_ID NUMBER NOT NULL,
4 DATE_FILLED DATE ,
5* PRIMARY KEY ( SKILL_ID, DEV_ID) )
12:01:04 ==> /
Table created.
1* insert into dev_skill values (3,4, to_date('02/02/2001 13:14','mm/dd/yyyy hh24:mi'))
12:02:53 ==> /
1 row created.
1* select to_char(date_filled, 'mm/dd/yyyy hh24:mi') from dev_skill
12:03:32 ==> /
TO_CHAR(DATE_FIL
----------------
02/02/2001 13:14
|
|
|
Re: Time field creation [message #18568 is a reply to message #18550] |
Tue, 05 February 2002 08:54   |
andrew again
Messages: 2577 Registered: March 2000
|
Senior Member |
|
|
Are you trying to auto populate that field??
CREATE TABLE ttt (pk NUMBER NOT NULL, date_filled DATE );
CREATE TRIGGER ttt_bef_ins
BEFORE INSERT
ON ttt
FOR EACH ROW
BEGIN
IF (:NEW.date_filled IS NULL)
THEN
:NEW.date_filled := SYSDATE;
END IF;
END;
/
INSERT INTO ttt (pk, date_filled) VALUES (1, SYSDATE);
INSERT INTO ttt (pk) VALUES (2);
SELECT * FROM ttt;
PK DATE_FILLED
--------------------------------------- -------------------
1 2/4/02 10:47:11 PM
2 2/4/02 10:47:15 PM
2 rows selected
|
|
|
Re: Time field creation [message #18570 is a reply to message #18550] |
Tue, 05 February 2002 09:12  |
andrew again
Messages: 2577 Registered: March 2000
|
Senior Member |
|
|
WRT my previous posting - you can just set the Default value in the table description - then no need for the trigger.
CREATE TABLE ttt (pk NUMBER NOT NULL, date_filled DATE Default sysdate);
|
|
|