I have a problem with a 3rd party product I use which handles external XML files. It causes the database to crash as a result of not being able to parse ampersands correctly (they're not escaped).
If I was to do this via SQLPlus I'd simply use 'SET DEFINE OFF' or 'SET ESCAPE ON' or both!
However, this process calls a function from a package.
Part of the body of the package is as follows:
CURSOR extractxml_c
IS
SELECT TRIM( extractvalue(column_value, '/TARLROW/HUSID')) husid,
TRIM( extractvalue(column_value, '/TARLROW/UKPRN')) ukprn,
TRIM( extractvalue(column_value, '/TARLROW/NUMHUS')) numhus,
TRIM( extractvalue(column_value, '/TARLROW/CAMPID')) campid,
TRIM( extractvalue(column_value, '/TARLROW/NAMECAT')) namecat,
TRIM( extractvalue(column_value, '/TARLROW/COURSEAIM')) courseaim,
TRIM( extractvalue(column_value, '/TARLROW/CTITLE')) ctitle,
TRIM( extractvalue(column_value, '/TARLROW/OWNSTU')) ownstu,
TRIM( extractvalue(column_value, '/TARLROW/STATUS') ) status,
TRIM( extractvalue(column_value, '/TARLROW/YEAR')) year,
TRIM( extractvalue(column_value, '/TARLROW/QUALENT2')) qualent2,
TRIM( extractvalue(column_value, '/TARLROW/COMDATE')) comdate,
TRIM( extractvalue(column_value, '/TARLROW/POSTCODE')) postcode,
TRIM( extractvalue(column_value, '/TARLROW/ETHNIC')) ethnic,
TRIM( extractvalue(column_value, '/TARLROW/DOMICILE')) domicile,
TRIM( extractvalue(column_value, '/TARLROW/YRLLINST') ) yrllinst,
TRIM( extractvalue(column_value, '/TARLROW/UCASAPPID')) ucasappid,
TRIM( extractvalue(column_value, '/TARLROW/OWNINST')) owninst,
TRIM( extractvalue(column_value, '/TARLROW/TTCID') ) ttcid,
TRIM( extractvalue(column_value, '/TARLROW/QUALENT3')) qualent3,
NULL pidm,
p_cohort chrt_code,
p_term_code term_code,
USER user_id,
SYSDATE activity_date,
'Banner: ESC_HST_CHRT_HINTAR_XML' data_origin,
NULL surrogate_id,
NULL version,
NULL vpdi_code,
gkkpsql.API_RetrieveRunSequence run_seq
FROM TABLE(XMLSequence( l_xmltype.extract('/TARLREPORT/TARLROWS/TARLROW'))) ;
I'd like to replace the ampersand characters pulled from the XML file using the replace function at the CTITLE section in the above code.
Something like this:
SELECT REPLACE('&' , '|| chr(38) || ')
However, I can't seem to get the syntax correct. On package compilation I keep getting missing right parenthesis errors.
I've used:
TRIM( extractvalue(column_value, (REPLACE('&' , '|| chr(38) || ') '/TARLROW/CTITLE')) ctitle,
and
REPLACE('&' , '|| chr(38) || ') TRIM( extractvalue(column_value, '/TARLROW/CTITLE')) ctitle,
and neither are working.
Any ideas how I'd replace characters pulled from a TRIM( extractvalue ) string function?
TIA