Elaine, I don’t think you need to create the horalocacao
and horadevolucao
, can do as follows:
Based on the data you passed, the table creation 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, in case you wanted the fields of horalocacao
and horadevolucao
converted to hours, would be 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 the DATE
saves date and time values, so you don’t need to create the horalocacao
and horadevolucao
, and if wanted to display only the time or date makes through the consultation.
Elaine, you can post the statement of the table?
– David
... Date location DATE NOT NULL, Time location DATE NOT NULL, Dated DATE, Horadevolucao DATE, Qtddias INTEGER , Value NUMBER(8,2) NOT NULL, Finished NUMBER(3) DEFAULT(0) NOT NULL);
– Elaine Xavier