Elaine, I believe you do not need to create the field of horalocacao
and horadevolucao
, you can do as follows:
Based on the data passed, the creation table would look like this:
CREATE TABLE LOCACAO (loc_codigo number(11)
,cli_codigo number(11) NOT NULL PRIMARY KEY
,vei_placa varchar(7) NOT NULL
,datalocacao date NOT NULL
,datadevolucao date NOT NULL
,qtddias integer(11)
,valordia number(8,2) NOT NULL
,finalizado number(3) DEFAULT(0) NOT NULL
);
The Inclusion:
INSERT INTO locacao
(loc_codigo
,cli_codigo
,vei_placa
,datalocacao
,datadevolucao
,qtddias
,valordia
,finalizado)
VALUES
(01
,1
,'ABC1234'
,TO_DATE('01/02/2016 08:30:00','DD/MM/YYYY HH24:MI:SS')
,TO_DATE('06/02/2016 07:00:00','DD/MM/YYYY HH24:MI:SS')
,5
,100.00
,1);
And the query, if you wanted the fields of horalocacao
and horadevolucao
converted to hours, would look like this:
SELECT loc_codigo
,cli_codigo
,vei_placa
,TO_CHAR(datalocacao,'DD/MM/RRRR') datalocacao
,TO_CHAR(datalocacao,'HH24:MI:SS') horalocacao
,TO_CHAR(datadevolucao,'DD/MM/RRRR') datadevolucao
,TO_CHAR(datadevolucao,'HH24:MI:SS') horadevolucao
,qtddias
,valordia
,finalizado
FROM locacao
This solution would be better because DATE
saves the date and time values, so you do not need to create the fields of horalocacao
and horadevolucao
, and if you wanted to display only the time or date you make through the query.