Home » SQL & PL/SQL » SQL & PL/SQL » ORA-01830 in XMLTABLE for DATE conversion (11g and 12c)
ORA-01830 in XMLTABLE for DATE conversion [message #663882] |
Thu, 22 June 2017 13:20  |
 |
hamsterbacke
Messages: 5 Registered: June 2017
|
Junior Member |
|
|
Hi all,
with the following setting I receive an ORA-01830 ("date format picture ends before converting entire input string" / "Datumsformatstruktur endet vor Umwandlung der gesamten Eingabezeichenfolge") for converting GEBURTSDATUM (given in German notation):
CREATE TABLE clobs
( MY_XML CLOB,
ID NUMBER
)
Insert into clobs (ID, MY_XML) values (1, '<RESULT><GEBURTSDATUM_AM>1953-06-07</GEBURTSDATUM_AM><GEBURTSDATUM>07.06.1953</GEBURTSDATUM></RESULT>');
SELECT *
FROM XMLTABLE(
'/RESULT'
PASSING XMLTYPE((SELECT my_xml FROM clobs WHERE ID=1))
COLUMNS
GEBURTSDATUM_AM DATE PATH 'GEBURTSDATUM_AM'
,GEBURTSDATUM DATE PATH 'GEBURTSDATUM'
);
However on 1 of 3 available Oracle databases (11g/12c) this error does not occur and we can't determine why.
There is the following workaround but it's rather ugly and maybe affecting performance:
SELECT *
FROM XMLTABLE(
'/RESULT'
PASSING XMLTYPE((SELECT my_xml FROM clobs WHERE ID=1))
COLUMNS
GEBURTSDATUM_AM DATE PATH 'GEBURTSDATUM_AM'
,GEBURTSDATUM DATE PATH 'replace(GEBURTSDATUM,"([0-9]{2})\.([0-9]{2})\.([0-9]{4})","$3-$2-$1")'
);
Does anybody have a clue how to set environment variables in order to have an efficient and "beautiful" conversion to DATE?
The NLS_... parameters only seem to affect the format of the output.
Best Regards,
Simon
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Re: ORA-01830 in XMLTABLE for DATE conversion [message #663950 is a reply to message #663942] |
Tue, 27 June 2017 10:32   |
_jum
Messages: 577 Registered: February 2008
|
Senior Member |
|
|
You did understand, that this has nothing to do with your ORACLE NLS_DATE_FORMAT, didn't you ?!
Then you could try something like:
SELECT nr, tag, datxt,
CASE WHEN tag='GEBURTSDATUM_AM'
THEN to_date(datxt,'YYYY-MM-DD')
ELSE to_date(datxt,'DD.MM.YYYY')
END datum
FROM xmltable('/RESULT/GEBURTSDATUM_AM | /RESULT/GEBURTSDATUM'
PASSING XMLTYPE('<RESULT><GEBURTSDATUM_AM>1953-06-07</GEBURTSDATUM_AM><GEBURTSDATUM>07.06.1953</GEBURTSDATUM></RESULT>')
COLUMNS
nr FOR ORDINALITY,
tag VARCHAR2(100) PATH 'local-name()',
datxt VARCHAR2(100) PATH '.');
NR TAG DATXT DATUM
---------------------------------------------------
1 GEBURTSDATUM_AM 1953-06-07 07.06.1953
2 GEBURTSDATUM 07.06.1953 07.06.1953
[Updated on: Tue, 27 June 2017 10:39] Report message to a moderator
|
|
|
Re: ORA-01830 in XMLTABLE for DATE conversion [message #663951 is a reply to message #663950] |
Tue, 27 June 2017 10:42   |
 |
Michel Cadot
Messages: 68757 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Er, this is not what is asked (implicitly by the given query which returns 1 line with 2 date columns), I don't see what you wanted to show and I don't see the advantage compare to the version I posted.
By the way, for me the result is:
SQL> SELECT nr, tag, datxt,
2 CASE WHEN tag='GEBURTSDATUM_AM'
3 THEN to_date(datxt,'YYYY-MM-DD')
4 ELSE to_date(datxt,'DD.MM.YYYY')
5 END datum
6 FROM xmltable('/RESULT/GEBURTSDATUM_AM | /RESULT/GEBURTSDATUM'
7 PASSING XMLTYPE('<RESULT><GEBURTSDATUM_AM>1953-06-07</GEBURTSDATUM_AM><GEBURTSDATUM>07.06.1953</GEBURTSDATUM></RESULT>')
8 COLUMNS
9 nr FOR ORDINALITY,
10 tag VARCHAR2(100) PATH 'local-name()',
11 datxt VARCHAR2(100) PATH '.');
NR TAG DATXT DATUM
---------- --------------- ------------ -------------------
1 GEBURTSDATUM_AM 1953-06-07 07/06/1953 00:00:00
2 GEBURTSDATUM 07.06.1953 07/06/1953 00:00:00
|
|
|
|
|
|
Re: ORA-01830 in XMLTABLE for DATE conversion [message #663960 is a reply to message #663958] |
Wed, 28 June 2017 01:29  |
 |
Michel Cadot
Messages: 68757 Registered: March 2007 Location: Saint-Maur, France, https...
|
Senior Member Account Moderator |
|
|
Quote:The NLS_DATE_FORMAT has no influence how ORACLE will accept a date in your XML, it has to be 'YYYY-MM-DD'!
Yes, and this is the problem, it depends on your version, patchset and even PSU.
Some use NLS, some use XML standard but none accept different date formats in the XML at the same time.
|
|
|
Goto Forum:
Current Time: Fri May 23 14:42:45 CDT 2025
|