Skip to content
Advertisement

Extract XML sqlQuery Issues in R – Querying Clob Column

I have a oracle DB table called CRS.CRS_FILES, with a column called FILE_DATA -inside that CLOB column is a large XML string.

Here is the first few lines of it:

it is set up with the following Xpath I want to query:

I am not sure what I am doing – I know that sqlQuery when passing SQL queries there are some minor format issues, but no matter what I try, my result looks like the following:

What am I doing wrong? I just want to extract the value Milwaukee Police Department (see below) (of course I would rename col to something like AGENCYNAME)

Advertisement

Answer

The EXTRACT(xml) function is deprecated. Instead, use XMLTABLE:

or, in R it should be the same with the double quotes escaped:

Which, for your test data:

Outputs:

| AGENCYNAME                  |
| :-------------------------- |
| Milwaukee Police Department |

If you do want to use EXTRACT then you need to specify the XML namespace:

Outputs:

| AGENCYNAME                  |
| :-------------------------- |
| Milwaukee Police Department |

db<>fiddle here

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement