In the code bellow, first there is a element that needs to be add, them in the rest of the code one attribute named t is created or updated.
declare
LOG_REFERENCE xmltype:=xmltype('<log />');
begin
select XMLQuery('
copy $p := $p1 modify insert node <update data="{$p2}" />
as last into $p/log
return $p
' PASSING LOG_REFERENCE AS "p1", to_char(systimestamp) AS "p2" RETURNING CONTENT)
INTO LOG_REFERENCE from dual;
select XMLQuery('
copy $i := $p1 modify(
if (fn:exists($i/log[1]/@t)) then (
replace value of node $i/log[1]/@t with $p2
) else (
insert node attribute t {$p2} into $i/log[1]
)
)
return $i
' PASSING LOG_REFERENCE AS "p1", to_char(systimestamp) AS "p2" RETURNING CONTENT)
INTO LOG_REFERENCE from dual;
dbms_output.PUT_LINE(LOG_REFERENCE.getClobVal());
end;
My problem is that i wanted to join the two modify into one xquery call like this
declare
LOG_REFERENCE xmltype:=xmltype('<log />');
begin
select XMLQuery('
copy $p := $p1 modify(
insert node <update data="{$p2}" />
as last into $p/log
)
copy $i := $p modify(
if (fn:exists($i/log[1]/@t)) then (
replace value of node $i/log[1]/@t with $p2
) else (
insert node attribute t {$p2} into $i/log[1]
)
)
return $i
' PASSING LOG_REFERENCE AS "p1", to_char(systimestamp) AS "p2" RETURNING CONTENT)
INTO LOG_REFERENCE from dual;
dbms_output.PUT_LINE(LOG_REFERENCE.getClobVal());
end;
In my head this is correct, But obviously im missing something. Or it can't be done in oracle xquery?
the error message that was given:
ORA-19114: XPST0003 - Error during parsing the XQuery expression: LPX-00801: XQuery syntax error at 'copy' 7 copy $i := $p modify( - ^ ORA-06512: em line 5