Меню

Date format picture ends before converting entire input string ошибка

My table has two DATE format attributes, however, when i try to insert value it throws an error: date format picture ends before converting entire input string.
Here is my attempted code:

insert into visit
values(123456, '19-JUN-13', '13-AUG-13 12:56 A.M.');

I think the problem is with 12:56 but Oracle documentation says date implies both date and time.

David Aldridge's user avatar

asked Jun 20, 2013 at 5:47

Buras's user avatar

Perhaps you should check NLS_DATE_FORMAT and use the date string conforming the format.
Or you can use to_date function within the INSERT statement, like the following:

insert into visit
values(123456, 
       to_date('19-JUN-13', 'dd-mon-yy'),
       to_date('13-AUG-13 12:56 A.M.', 'dd-mon-yyyy hh:mi A.M.'));

Additionally, Oracle DATE stores date and time information together.

answered Jun 20, 2013 at 5:54

ntalbs's user avatar

ntalbsntalbs

28.1k8 gold badges64 silver badges83 bronze badges

4

you need to alter session

you can try before insert

 sql : alter session set nls_date_format = 'YYYY-MM-DD HH24:MI:SS'

answered Nov 3, 2016 at 13:50

afeef's user avatar

afeefafeef

4,18611 gold badges33 silver badges64 bronze badges

0

What you’re trying to insert is not a date, I think, but a string. You need to use to_date() function, like this:

insert into table t1 (id, date_field) values (1, to_date('20.06.2013', 'dd.mm.yyyy'));

answered Jun 20, 2013 at 5:53

Andrew Logvinov's user avatar

Andrew LogvinovAndrew Logvinov

20.8k6 gold badges52 silver badges53 bronze badges

I had this error today and discovered it was an incorrectly-formatted year…

select * from es_timeexpense where parsedate > to_date('12/3/2018', 'MM/dd/yyy')

Notice the year has only three ‘y’s. It should have 4.

Double-check your format.

answered Dec 3, 2018 at 15:38

birwin's user avatar

birwinbirwin

2,4242 gold badges21 silver badges40 bronze badges

1

Hi

I have a problem with executing a procedure with date parameter from SQL Developer and I would need some help here.

I have a package and procedure inside with next signature:

Procedure MyProc(par_Year In Date, par_Exit_Code Out PLS_Integer, par_Exit_Message Out VarChar2) As    var_Input_Date Date := To_Date(par_Year, 'DD.MM.YYYY'); -- User Input...End;

I call this procedure from APEX application as Process:

Declare  var_Exit_Code PLS_Integer;  var_Exit_Message VarChar2(4000);Begin  MyPackage.MyProc(To_Date(:P10_Year, 'DD.MM.YYYY'), var_Exit_Code, var_Exit_Message);...End;

and it works Ok. I supply Year over DatePicker control, where I choose one date.

Now I would like to call this same procedure from SQL Developer, where I supply some date, to get some more info from my code. I call it this way:

Declare  var_Exit_Code PLS_Integer;  var_Exit_Message VarChar2(4000);  var_Input VarChar2(25) := '10.01.2018';Begin  MyPackage.MyProc(To_Date(var_Input, 'DD.MM.YYYY'), var_Exit_Code, var_Exit_Message);...End;

And when I run this PL/SQL block I get next error message:

ORA-01830: date format picture ends before converting entire input string.

What I’m doing wrong here? Why the same code work from Apex app, but not from SQL Developer?

In SQL Developer I have Database > NLS set to: DD.MM.YYYY HH24:Mi:SS, if this help anything to solve the problem.

Any clear explanation an solutions are welcome.

BB

I am trying to run the query on an Oracle database

select 
  to_date(trunc(sysdate) || '13:00:00','DD-MON-YY HH24:MI:SS') 
from dual;

and get the error

ORA-01830: date format picture ends before converting entire input string

Please suggest.

miracle173's user avatar

asked Aug 29, 2015 at 10:30

user1782805's user avatar

0

SQL> alter session set nls_Date_format = 'DD-MON-YY HH24:MI:SS';

Session altered.

SQL> select trunc(sysdate, 'DD') + 13/24 from dual;

TRUNC(SYSDATE,'DD'
------------------
29-AUG-15 13:00:00

answered Aug 29, 2015 at 10:55

Balazs Papp's user avatar

Balazs PappBalazs Papp

39k2 gold badges23 silver badges43 bronze badges

3

This is a runtime error. The date function has a problem to convert the date string. so display the date string to see what you want to convert:

select trunc(sysdate) || '13:00:00' from dual

answered Aug 30, 2015 at 1:49

miracle173's user avatar

miracle173miracle173

7,52624 silver badges41 bronze badges

to_date( trunc( sysdate ) || ’13:00:00′,’DD-MON-YY HH24:MI:SS’ )

An Innocent-looking query … but with nasty, implicit Type Conversions all over the place.

Breaking it down:

  • Start with sysdate(). (DATE Data Type)

  • Truncate that value, to remove the Time portion. (Still a DATE Data Type)

  • Implicitly cast that value into a VARCHAR, using whatever NLS_DATE_FORMAT happens to be in force, then concatenate the time bit on the end of that, without any intervening space to separate the two bits, and finally

  • Try to convert the resulting varchar value back into a DATE Data Type, using the explicit format given (which, by the way, includes a space between the data and Time portions).

If those internal conversions don’t give you something that exactly matches that Date/Time parsing pattern? Boom!

Remove the last to_date() call and see what [varchar] value you’re actually getting.

I suspect this will work if you remove the explicit Date/Time «pattern» and use whatever [NLS setting] the database is currently using.

answered Mar 13, 2020 at 12:09

Phill  W.'s user avatar

Phill W.Phill W.

7,4431 gold badge10 silver badges20 bronze badges

totn Oracle Error Messages


Learn the cause and how to resolve the ORA-01830 error message in Oracle.

Description

When you encounter an ORA-01830 error, the following error message will appear:

  • ORA-01830: date format picture ends before converting entire input string

Cause

You tried to enter a date value, but the date entered did not match the date format.

Resolution

The option(s) to resolve this Oracle error are:

Option #1

This error can occur when you try to enter a date value without using the TO_DATE function.

In Oracle, the default date format is generally DD-MON-YYYY. If you try to enter a date value that does not comply with this format, you need to use the TO_DATE function.

For example, if you tried to execute the following SQL statement:

INSERT INTO supplier
VALUES
(1, 'IBM', '13-DEC-2004 6:56 PM');

You would receive the following error message:

Oracle PLSQL

To correct this error, you can use the TO_DATE function as follows:

INSERT INTO supplier
VALUES
(1, 'IBM', TO_DATE('13-DEC-2004 6:56 PM', 'dd-mon-yyyy hh:mi PM'));

Вопрос:

Мой запрос (при TO_TIMESTAMP приложения) не выполняется с этой ошибкой, несмотря на использование функции TO_TIMESTAMP.

INSERT INTO MY_TABLE_NAME (
UPDATED_DATE,
CREATED_DATE,
TEST_SUBJECT,
THIRD_DATE
) VALUES (
TO_TIMESTAMP('2018-05-31 14:45:32.000', 'YYYY-MM-DD HH24:MI:SSxFF'),
TO_TIMESTAMP('2018-05-31 14:45:32.000', 'YYYY-MM-DD HH24:MI:SSxFF'),
'test',
TO_TIMESTAMP('2018-06-09 14:45:00.000', 'YYYY-MM-DD HH24:MI:SSxFF')
)

Здесь сообщение об ошибке –

{FAILED after 2 ms}
java.sql.SQLDataException: ORA-01830: date format picture ends before converting entire input string

Эта ошибка возникает только в одной среде, но отлично работает в других средах.

Вручную выполнение запроса также отлично работает.

Формат временной метки сеанса во всех средах одинаковый (обновляется триггером при входе в систему).

Лучший ответ:

[TL; DR] Используйте литералы Timestamp, чтобы избежать этой проблемы:

INSERT INTO MY_TABLE_NAME (
  UPDATED_DATE,
  CREATED_DATE,
  TEST_SUBJECT,
  THIRD_DATE
) VALUES (
  TIMESTAMP '2018-05-31 14:45:32.000',
  TIMESTAMP '2018-05-31 14:45:32.000',
  'test',
  TIMESTAMP '2018-06-09 14:45:00.000'
);

Если вы не можете проверить NLS_NUMERIC_CHARACTERS базы данных/сеанса NLS_NUMERIC_CHARACTERS. Если десятичная точка отсутствует . то модель формата x не будет соответствовать . но будет соответствовать любому типу, который использует база данных/сеанс, и строка не будет сопоставлена.

SQL Fiddle

Настройка схемы Oracle 11g R2:

CREATE TABLE MY_TABLE_NAME (
  UPDATED_DATE TIMESTAMP,
  CREATED_DATE TIMESTAMP,
  TEST_SUBJECT VARCHAR2(20),
  THIRD_DATE   TIMESTAMP
);

Запрос 1:

-- Set decimal separator to "." and thousands separator to ","
ALTER SESSION SET NLS_NUMERIC_CHARACTERS = '.,'    

INSERT INTO MY_TABLE_NAME (
  UPDATED_DATE,
  CREATED_DATE,
  TEST_SUBJECT,
  THIRD_DATE
) VALUES (
  TO_TIMESTAMP('2018-05-31 14:45:32.000', 'YYYY-MM-DD HH24:MI:SSxFF'),
  TO_TIMESTAMP('2018-05-31 14:45:32.000', 'YYYY-MM-DD HH24:MI:SSxFF'),
  'test',
  TO_TIMESTAMP('2018-06-09 14:45:00.000', 'YYYY-MM-DD HH24:MI:SSxFF')
)

SELECT * FROM MY_TABLE_NAME

Результаты:

|          UPDATED_DATE |          CREATED_DATE | TEST_SUBJECT |            THIRD_DATE |
|-----------------------|-----------------------|--------------|-----------------------|
| 2018-05-31 14:45:32.0 | 2018-05-31 14:45:32.0 |         test | 2018-06-09 14:45:00.0 |

Запрос 2:

-- Set decimal separator to "," and thousands separator to " "
ALTER SESSION SET NLS_NUMERIC_CHARACTERS = ', '

INSERT INTO MY_TABLE_NAME (
  UPDATED_DATE,
  CREATED_DATE,
  TEST_SUBJECT,
  THIRD_DATE
) VALUES (
  TO_TIMESTAMP('2018-05-31 14:45:32.000', 'YYYY-MM-DD HH24:MI:SSxFF'),
  TO_TIMESTAMP('2018-05-31 14:45:32.000', 'YYYY-MM-DD HH24:MI:SSxFF'),
  'test',
  TO_TIMESTAMP('2018-06-09 14:45:00.000', 'YYYY-MM-DD HH24:MI:SSxFF')
)

Результаты:

ORA-01830: date format picture ends before converting entire input string 

Другое решение – использовать 'YYYY-MM-DD HH24:MI:SS.FF' в качестве модели формата, а не полагаться на модель формата x, чтобы всегда быть согласованной между экземплярами/сеансами.

0 0 голоса
Рейтинг статьи
Подписаться
Уведомить о
guest

0 комментариев
Старые
Новые Популярные
Межтекстовые Отзывы
Посмотреть все комментарии

А вот еще интересные материалы:

  • Яшка сломя голову остановился исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного исправьте ошибки
  • Ясность цели позволяет целеустремленно добиваться намеченного где ошибка
  • Datastore usage on disk vmware ошибка
  • Datakom dkg 309 сброс ошибок