XML parsing failed in SELECT query - sql

I am running the SELECT query from the Oracle SQL developer IDE on my RHEL box as below
SELECT count(*)
From xyz
WHERE xmltype(xyz.xmlColumn).existsNode('//name=""') = 1;
Above query works fine if I execute for single record. But when I execute it for the whole table it fails with the error:
ORA-31011: XML parsing failed
ORA-19202: Error occurred in XML processing
LPX-00210: expected '<' instead of 'C'
Error at line 1
ORA-06512: at "SYS.XMLTYPE", line 272
ORA-06512: at line 1
31011. 00000 - "XML parsing failed"
*Cause: XML parser returned an error while trying to parse the document.
*Action: Check if the document to be parsed is valid.
Any pointers on above will help me.

include /text in your xpath. like
select (COLUM_NAME).extract('//parentNode/chileNode/text()').getStringVal() as Colum_Name from TableName where UUID='Value'

Oracle is complaining that "xyz.xmlColumn" is not a valid xml column or type. It expects <element>....</element> format

Your problem is what is stored in your CLOB is not an XML document as it is missing a root node. Since you are scanning the whole document in your extract you could just wrap it in an element to ensure you have 1 and only 1 root, at which point your XMLTYPE cast would work.
SELECT
XMLTYPE(''||clob_field||'').EXTRACT('//se/text()').getStringVal()
FROM tablename

Related

Cannot query my container using the GridDB Shell?

I have a device container with the name 1cbfce15ec4d which houses some my data. I know for a fact there's data in there, but when I try a simple query in the griddb shell, I got the following error:
gs[public]> sql select * from 1cbfce15ec4d;
D20332: An unexpected error occurred while executing a SQL. : msg=[[240001:SQL_COMPILE_SYNTAX_ERROR] Parse SQL failed, reason = Syntax error: 1cbfce15ec4d; on executing query (sql="select * from 1cbfce15ec4d") (db='public') (user='admin') (appName='gs_sh') (clientId='a6d92f48-e558-440-86dd-a05e949fa726:1') (clientNd='{clientId=3, address=127.0.0.1:55744}') (address=127.0.0.1:20001, partitionId=983)]
I am not exactly sure what is going on here -- at first I assumed my data must be corrupt or empty, but that is not the case. It seems to be a case of the shell dying trying to process something about that container name.
Any ideas?
According to the manual :
"If the name of a table or a column contains characters other than ASCII alphanumeric characters and underscore, or if the first character of the name is a number in a SQL statement, enclose the name with double quotation marks."
Try select * from "1cbfce15ec4d"

SQL - LPX-00242: invalid use of ampersand ('&') character (use &)

I'm trying to run the below sql query.
SELECT sr.resultid, xt2.*
FROM RESULTS sr,
XMLTABLE('/extraInfo/resultsViewData'
PASSING XMLType(sr.extrainfo)
COLUMNS
docketNumber VARCHAR2(35) PATH 'docketNumber',
dateFiled VARCHAR2(35) PATH 'dateFiled',
nosDescription VARCHAR2(70) PATH 'nosDescription',
courtname VARCHAR2(100) PATH 'courtname',
chapter VARCHAR2(35) PATH 'chapter'
) xt2
WHERE sr.profileId = '7dd76222';
NOTE: sr.extrainfo has the value
'<extraInfo><resultsViewData><courtname>FL Circuit & County - Santa Rosa</courtname></resultsViewData></extraInfo>'
Even though I use '& amp ;' instead of '&', I still get the below error,
ORA-31011: XML parsing failed
ORA-19213: error occurred in XML processing at lines 1
LPX-00242: invalid use of ampersand ('&') character (use &)
ORA-06512: at "SYS.XMLTYPE", line 272
ORA-06512: at line 1
31011. 00000 - "XML parsing failed"
*Cause: XML parser returned an error while trying to parse the document.
*Action: Check if the document to be parsed is valid.
Sometimes I even get the error,
LPX-00242: invalid use of ampersand ('&') character (use &amp;)
Is there any way to overcome this issue?
Try:
set define off;
Then execute your query;
If you want more info on what set define off; does: When or Why to use a "SET DEFINE OFF" in Oracle Database
I am not able to reproduce your issue at first place.
But still if you are getting the issue then try to use dbms_xmlgen.convert to convert your string as following:
'<extraInfo><resultsViewData><courtname>'
|| dbms_xmlgen.convert('FL Circuit & County - Santa Rosa')
|| '</courtname></resultsViewData></extraInfo>'
db<>fiddle demo
Cheers!!

Hive -character '<EOF>' not supported here

Select * from mytable where field=
'ce7bd3d4-dbdd-407e-a3c3-ce093a65abc9;cdb597073;7cf6cda5fc'
Getting Below Error while running above query in Hive
FAILED: ParseException line 1:92 character '' not supported here
<EOF> here means End Of File. When you get an "unexpected End Of File" error it means the parser reached the end of the query unexpectedly. This typically happens when the parser is expecting to find a closing character, such as when you have started a string with ' or " but have not closed the string (with the closing ' or ").
When you come across these types of errors it is good to check that your query can be parsed correctly. In addition, the error gives you the location where the parser failed: line 1:92 in this case. You can usually look at this location (character 92 of the query) and work backwards to find the problem character.
Try adding the database name to the "from" statement as below.
Select * from my_db_name.mytable where field= 'ce7bd3d4-dbdd-407e-a3c3-
ce093a65abc9;cdb597073;7cf6cda5fc';
Hive uses the default database when no database was previously specified.

how insert ODI step error message in to Oracle table, if the error message has single quotes and colons

I'm trying to insert ODI step error message into oracle table.
I captured the error message using <%=odiRef.getPrevStepLog("MESSAGE")%>.
ODI-1226: Step PRC_POA_XML_synchronize fails after 1 attempt(s).
ODI-1232: Procedure PRC_POA_XML_synchronize execution fails.
ODI-1227: Task PRC_POA_XML_synchronize (Procedure) fails on the source XML connection XML_PFIZER_LOAD_POA_DB_DEV.
Caused By: java.sql.SQLException: class java.sql.SQLException
oracle.xml.parser.v2.XMLParseException: End tag does not match start tag 'tns3:ContctID'.
at com.sunopsis.jdbc.driver.xml.SnpsXmlFile.readDocument(SnpsXmlFile.java:459)
at com.sunopsis.jdbc.driver.xml.SnpsXmlFile.readDocument(SnpsXmlFile.java:469)
When I try to insert this into a table, I'm getting the following error:
Missing IN or OUT parameter at index:: 1
I tried with substr, replace. Nothing works as in middle of the error message we have a single quotes 'tns3:ContctID'.
Is there any way to insert this into a table?
that's a tough one if you want to use pure java BeanShell and you've given way too little details to get short and straight answer, like
how do you try to insert this (command on source/target, bean shell only, Oracle SQL +jBS, jython, groovy etc...)
The problem here is not only quotes but also newlines.
To replace them is even more difficult as every parsing step <%, <?, <# requires different trick to define those literals
What will work for sure is if you write Jython task for inserting log data (Jython in technology).
There you may use Python ability for multiline string literals
simply:
⋮
err_log = """
<?=odiRef.getPrevStepLog("MESSAGE")?>
"""
⋮
I faced this error few days back . I applied below mentioned solution in ODI ...
Use - q'#<%=odiRef.getPrevStepLog("MESSAGE")%>#'
This will escape inverted comma (') for INSERT statement.
I have used this in my code and it is working fine :)
For example -
select 'testing'abcd' from dual;
this query will give below error
"ORA-01756: quoted string not properly terminated"
select q'#testing'abcd#' from dual;
This query gives no error and we get below response in SQL Developer
testing'abcd

extractvalue fails on using xpath with quotes

I am getting "ORA-21560: argument 3 is null, invalid, or out of range" error on running query:
SELECT extractvalue(xmltype(blob2clob(shblobdata.blobdata)),
'/booked-order/ads/online-content[name="quantity"]/value')
FROM shblobdata
WHERE id=...;
the full error is:
ORA-21560: argument 3 is null, invalid, or out of range
ORA-06512: at "SYS.DBMS_LOB", line 978
ORA-06512: at "MORAS.BLOB2CLOB", line 14
21560 . 00000 - "argument %s is null, invalid, or out of range"
*Cause: The argument is expecting a non-null, valid value but the
argument value passed in is null, invalid, or out of range.
Examples include when the LOB/FILE positional or size
argument has a value outside the range 1 through (4GB - 1),
or when an invalid open mode is used to open a file, etc.
*Action: Check your program and correct the caller of the routine
to not pass a null, invalid or out-of-range argument value.
I have tried to change "quantity" to ''quantity'' (changing single quote to two apostrophes), but got the same error.
The content of blob is:
<?xml version="1.0" encoding="utf-8"?>
<booked-order>
<ads>
<online-content>
<name>quantity</name>
<value>19872</value>
</online-content>
</ads>
</booked-order>
The problem is in your custom function MORAS.BLOB2CLOB.
Also the error message says clearly ORA-06512: at "MORAS.BLOB2CLOB", line 14
The extract itself is ok, when you keep out BLOB2CLOB and test with
SELECT EXTRACTVALUE (xmltype ( (shblobdata.blobdata)), '/booked-order/ads/online-content[name="quantity"]/value')
FROM (SELECT '<?xml version="1.0" encoding="utf-8"?>
<booked-order>
<ads>
<online-content>
<name>quantity</name>
<value>19872</value>
</online-content>
</ads>
</booked-order>
' blobdata
FROM DUAL) shblobdata
;
it returns 19872
I'd first debug your function blob2clob with
SELECT blob2clob(shblobdata.blobdata)
FROM shblobdata
WHERE id=...;
And if that works ok continue on to the XML parts.
The exception is clearly hurled by BLOB2CLOB(), which is not an Oracle built-in. It's something you've written yourself or lifted from somewhere on the interwebs. So there's not much we can do to help regarding it.
The more general point is, why are you storing XML in a BLOB? The best apporach is to store it in a column defined as Oracle's XMLTYPE datatype. Otherwise store it as a CLOB.