I have a varchar2
field containing some text, including accented characters ( e.g. à
,è
,...) and other non literal characters (<
,!
,;
...).
I need to transform this field in html compliant format, by using one of the following output formats:
input output1 output2
á á á
â â â
Here is an example of starting data and two possible needed output, with something I unsuccessfully tried:
with test(starting, needed, needed2) as (
select 'abc À. < ! ; à ',
'abc À. < ! ; à',
'abc À. < ! ; à'
from dual)
select starting, needed, needed2, UTL_I18N.escape_reference(starting) as result, 'UTL_I18N' as function from test union all
select starting, needed, needed2, convert(starting, 'US7ASCII' ) , 'convert' from test union all
select starting, needed, needed2, HTF.ESCAPE_SC(starting) , 'htf' from test union all
select starting, needed, needed2, asciiStr(starting) , 'ascii' from test union all
select starting, needed, needed2, dbms_xmlgen.convert(starting) , 'dbms_xmlgen' from test union all
select starting, needed, needed2, TRANSLATE(starting USING CHAR_CS) , 'translate' from test;
The output (needed and obtained so far):
STARTING NEEDED NEEDED2 RESULT FUNCTION
-------------------- ---------------------------------------- ---------------------------------------- ------------------------------ -----------
abc À. < ! ; à abc À. < ! ; à abc À. < ! ; à abc À. < ! ; à UTL_I18N
abc À. < ! ; à abc À. < ! ; à abc À. < ! ; à abc ?. < ! ; ? convert
abc À. < ! ; à abc À. < ! ; à abc À. < ! ; à abc À. < ! ; à htf
abc À. < ! ; à abc À. < ! ; à abc À. < ! ; à abc \00B7. < ! ; \2026 ascii
abc À. < ! ; à abc À. < ! ; à abc À. < ! ; à abc À. < ! ; à dbms_xmlgen
abc À. < ! ; à abc À. < ! ; à abc À. < ! ; à abc À. < ! ; à translate
The resulting string is used to build a file compliant with Excel (even Excel 2003), by applying a transformation on a XML; this does not support accented characters, so I need a conversion.
I could use some regular expressions, but I was trying to get a better solution. I'm using Oracle 11.2.0.3.0.