Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a method in PL/SQL to convert/encode text to XML compliant text?

Tags:

xml

oracle

plsql

I have a colleague who needs to convert text from a PL/SQL method into XML compliant text, as he is constructing a excel spreadsheet by updating a text template.

Is there a method in PL/SQL to convert/encode text to XML compliant text?

like image 726
Bravax Avatar asked Jan 20 '09 16:01

Bravax


People also ask

What is Dbms_xmlgen?

The DBMS_XMLGEN Package is used to transform results of SQL queries into a canonical XML format.

What is XMLForest?

XMLForest converts each of its argument parameters to XML, and then returns an XML fragment that is the concatenation of these converted arguments. If value_expr is a scalar expression, then you can omit the AS clause, and Oracle Database uses the column name as the element name.


2 Answers

Well, if you just want to convert XML characters, you'll want to do something like...

  outgoing_text := DBMS_XMLGEN.CONVERT(incoming_text)

Where outgoing_text and incoming_text are both VARCHAR2 or CLOB.

You can specify a second argument, but it defaults to DBMS_XMLGEN.ENTITY_ENCODE... it can also decode XML entities by passing DBMS_XMLGEN.ENTITY_DECODE as a second argument.

like image 145
Powerlord Avatar answered Nov 08 '22 09:11

Powerlord


Later versions of oracle have a built in XML package for manipulating XML data.
For example, is this the sort of thing your colleague wants to do?:

SELECT DBMS_XMLGEN.getXML('SELECT * FROM emp') FROM dual;
like image 25
hamishmcn Avatar answered Nov 08 '22 07:11

hamishmcn