Tuesday, January 2, 2024

oracle: SQL Error: ORA-01861: literal does not match format string , 01861. 00000 - "literal does not match format string"


 >PROBLEM


The attempt to insert data from a migrated code from PostgreSQL to on a Oracle database using automatic generator resulted a generic message error.


- The insert command:

INSERT INTO loc_users( loc_users_id, nome, login, email, senha, nascimento, celular, idioma, ativo ) VALUES ( 1, 'Yuzefo', 'Abibeh', 'william@copel.com.br', 'Apukoyal', '1951-08-31', '05292770147', 'english', 1);



- Oracle returns a generic message not providing a tip to a specific field:


SQL Error: ORA-01861: literal does not match format string

01861. 00000 -  "literal does not match format string"

*Cause:    Literals in the input must be the same length as literals in

           the format string (with the exception of leading whitespace).  If the

           "FX" modifier has been toggled on, the literal must match exactly,

           with no extra whitespace.

*Action:   Correct the format string to match the literal.


>SOLUTION


Check your DDL comparing with the insert statement.

Usually operations involving date, time and timestamp cause issues during migration.

In this example, the field "nascimento" (born date in portuguese) has an incompatible format for date as concerns Oracle's usage.


Set TO_DATE() function:

TO_DATE('1951-08-31', 'YYYY-MM-DD')


INSERT INTO loc_users( loc_users_id, nome, login, email, senha, nascimento, celular, idioma, ativo ) VALUES ( 1, 'Yuzefo', 'Abibeh', 'william@copel.com.br', 'Apukoyal', TO_DATE('1951-08-31', 'YYYY-MM-DD'), '05292770147', 'english', 1);



>ENV

oracle 11g


No comments:

Post a Comment

eclipse: java: SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder" or Exception in thread "main" java.lang.NoClassDefFoundError: org/slf4j/impl/StaticLoggerBinder

  >PROBLEM Using Eclipse, you try to run a simple logging test using "org.slf4j.Logger" like the sample below: package Test; im...