0

I need to insert custom date time in the oracle database where the ITEM_TIME_DATE column has the TIMESTAMP data type.

Here is my query:

INSERT INTO items 
    (ITEM_AUTHOR_ID, ITEM_TITLE, ITEM_DESCRIPTION, ITEM_TIME_DATE, ITEM_STATUS) 
    VALUES 
    ('0', 'test title', 'test des', TO_TIMESTAMP('12-23-2015 8:00 PM', 'MM-DD-YYYY HH24:MI:SS'), 0);

Though the custom date should convert to a timestamp format, but i am getting this error:

ORA-01858: a non-numeric character was found where a numeric was expected

I am using Oracle 11.2.0.2.0 (Windows 10) 64-bit

3 Answers 3

2

The date format in the TO_TIMESTAMP call doesn't match the data. Use:

INSERT INTO items 
  (ITEM_AUTHOR_ID, ITEM_TITLE, ITEM_DESCRIPTION, ITEM_TIME_DATE, ITEM_STATUS) 
VALUES 
  ('0', 'test title', 'test des', TO_TIMESTAMP('12-23-2015 8:00 PM', 'MM-DD-YYYY HH:MI AM'), 0);

Best of luck.

Sign up to request clarification or add additional context in comments.

Comments

1

You need to remove the :SS or add seconds :00 to your time, and add AM to the format.

This works:

INSERT INTO items 
    (ITEM_AUTHOR_ID, ITEM_TITLE, ITEM_DESCRIPTION, ITEM_TIME_DATE, ITEM_STATUS) 
    VALUES 
    ('0', 'test title', 'test des', TO_TIMESTAMP('12-23-2015 8:00:00 PM', 'MM-DD-YYYY HH:MI:SS AM'), 0);

Comments

0

You have used HH24:MI:SS as the date format and so your insert value should be

TO_TIMESTAMP('12-23-2015 8:00', 'MM-DD-YYYY HH24:MI:SS')

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.