Click here to Skip to main content
15,884,237 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi - I have a procedure which is supposed to insert the records to table1 using merge statement,while trying to execute the proc,am getting "ORA-01861: literal does not match format string".

It might be due to mismatch with data defined columns where the source table has null values.

here DATE_CREATED column from source has null values as well as the date format is'14-JAN-2018.

What I have tried:

create or replace PROCEDURE PROC1 AS
BEGIN
MERGE INTO table1 u
USING view m
ON (u.USER_ID = m.userID)
WHEN MATCHED THEN UPDATE SET
u.ACTIVE = m.ACTIVE,
u.DATE_CREATED = m.DATE_CREATED,
u.CREATED_YEAR_MON = to_char(m.DATE_CREATED, 'YYYY-MM'),
u.CREATED_YEAR = to_char(m.DATE_CREATED, 'YYYY'),
u.CREATED_MON = to_char(m.DATE_CREATED, 'MM'),
u.SECTOR = m.SECTOR,
u.REGION = m.REGION
WHEN NOT MATCHED THEN INSERT
VALUES (m.userID, m.ACT, m.DATE_CREATED, to_char(m.DATE_CREATED, 'YYYY-MM'), to_char(m.DATE_CREATED, 'YYYY'),
to_char(m.DATE_CREATED, 'MM'), m.SECTOR, m.REGION, CURRENT_DATE);
END;
Posted
Comments
Richard Deeming 31-May-18 16:20pm    
A good example of why you should never store dates as strings! :)

Date Data Types[^]

If you store the values properly, they're a lot easier to deal with, and they take up less space as well.
GJSS 31-May-18 16:36pm    
The data type of both source and target tables are DATE datatype only
Jörgen Andersson 1-Jun-18 15:11pm    
But you're trying to store Chars in those DATE columns, that won't work.
If you want a part of a date field you should use EXTRACT. https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions050.htm
But that should be done when you need the part, it should never be stored like that, that's bad practice.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900