How to insert time into Oracle?

Asked

Viewed 1,446 times

2

I need to save only the hour and minutes (seconds make no difference, so having or not, whatever) I should use TIME or TIMESTAMP ?

I started doing with TIMESTAMP(6), but I’m having a hard time insert, what I must do ?

my insert:

INSERT INTO EXEMPLO (DESCRICAO, NUMEROMAXIMO, HORAENTRADA, HORASAIDA) 
 VALUES ('Descrição', '50', '15:51:00', '16:51:00');
  • Just to clarify a few things: Oracle does not have a field of only hours (time). The data type date stores: century, year, month ,day, hours, minutes and seconds. You can create these columns date and time and insert a date like: 1-1-1900, and only work with the hours and minutes. The other option is to use text (but this complicates any account you want to do with these values)

1 answer

2


You can use the TO_DATE;

INSERT INTO EXEMPLO (DESCRICAO, NUMEROMAXIMO, HORAENTRADA, HORASAIDA) 
 VALUES ('Descrição', '50', TO_DATE('15:51:00','HH24:MI:SS') , TO_DATE('16:51:00','HH24:MI:SS'))
  • this HH24:MI,SS does not need to put for the time out too ?

  • truth I forgot

  • it returns me ORA-01722: invalid number

  • You tested right on the oracle?

  • This NUMEROMAXIMO field is varchar2 even?

  • tested directly on Oracle, the maximum field is number.

  • In mine it worked

Show 2 more comments

Browser other questions tagged

You are not signed in. Login or sign up in order to post.