Pregunta

I need to run this sql statement:

INSERT INTO JSP_CONTROL (estado,hora_inicio,fecha,tipo) VALUES
('ACTUALIZANDO',to_char(sysdate, 'HH24:mi:SS'),sysdate,'uno');

this is the table:

CREATE TABLE "GCUENTAS"."JSP_CONTROL"
(
"ESTADO" VARCHAR2(20 BYTE),
"HORA_INICIO" TIMESTAMP (6),
"HORA_TERMINO" TIMESTAMP (6),
"FECHA" DATE,
"TIPO" VARCHAR2(20 BYTE)

The problem is here: to_char(sysdate, 'HH24:mi:SS'), it's supposed to insert something like "16:01:35", but insert "16/01/35" (in DD/MM/YY format).

making some test like

SELECT to_char(sysdate, 'HH24:mi:SS') FROM DUAL

are succesfull

This is the message error:

Error que empieza en la línea 1 del comando:
INSERT INTO JSP_CONTROL (estado,hora_inicio,fecha,tipo) VALUES
  ('ACTUALIZANDO',to_char(sysdate, 'HH24:mi:SS'),sysdate,'uno')
Informe de error:
Error SQL: ORA-01843: mes no válido
01843. 00000 -  "not a valid month"
*Cause:    
*Action:
Error que empieza en la línea 1 del comando:
INSERT INTO JSP_CONTROL (estado,hora_inicio,fecha,tipo) VALUES
  ('ACTUALIZANDO',to_char(sysdate, 'HH24:mi:SS'),sysdate,'uno')
Informe de error:
Error SQL: ORA-01843: mes no válido
01843. 00000 -  "not a valid month"
*Cause:    
*Action:
¿Fue útil?

Solución

hora_inicio is a timestamp column, but you are passing a character value to it in the insert statement because of the to_char() call.

While processing the character value you provided Oracle tries to convert it into a timestamp (because the target column is a timestamp). But a time like 23:56:12 is most definitely not a valid date.

If you are trying to insert only the time part into that column, that won't work. A timestamp always contains a date. There is no datatype in Oracle to only hold a time.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top