I need to do some processing on some data from an Oracle database and then print it as XML. I’m using XMLElement and the methods that go with it. However, I’ve found that if I pass a varchar into a PL/SQL function and then pass that variable to XMLElement, it prints the variable name instead of its content, like so:
create or replace function gen_elem_tmp(label1 varchar2, value1 varchar2)
return XMLType
is
result_xml XMLType;
begin
select XMLElement(label1,value1) into result_xml from dual;
return result_xml;
end;
> select gen_elem_tmp('myname','myvalue') from dual;
GEN_ELEM_TMP('MYNAME','MYVALUE')
------------------------------------------------
<LABEL1>myvalue</LABEL1>
I’m guessing this is XMLElement ‘helpfully’ interpreting my variable name as a database column. Is there any way of getting it to use my variable’s contents, instead?
Try this:
This appears to be by design. Without
EVALNAME,label1is used as a literal instead of a variable.(In normal SQL or PL/SQL programming this seems like a really awful idea. Maybe it makes sense in an XML context?)