Skip to Main Content
  • Questions
  • "APOS;" appearinig in SQL*PLus output. Want actual apostrophe instead.

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Michael.

Asked: January 23, 2018 - 4:25 pm UTC

Last updated: January 25, 2018 - 1:48 am UTC

Version: Oracle Database 12c Enterprise Edition Release 12.1.0.2.0 - 64bit Production

Viewed 10K+ times! This question is

You Asked

How can I suppress the appearance of "apos;" and similar web-friendly tags from my SQL*Plus output. In place of "apos;" I'm actually looking for the apostrophe "'". Thank you!!
- Mike Kemp

with LiveSQL Test Case:

and Connor said...

You can use DBMS_XMLGEN to do a conversion for you

SQL> with emp as ( select 123 empno, 'O''Brien' ename from dual )
  2  select
  3    xmlelement("blah",
  4      xmlforest(e.empno as "empid",
  5                e.ename as "name")
  6      )
  7  from emp e;

XMLELEMENT("BLAH",XMLFOREST(E.EMPNOAS"EMPID",E.ENAMEAS"NAME"))
------------------------------------------------------------------------------------------
<blah><empid>123</empid><name>O&apos;Brien</name></blah>

SQL>
SQL> set serverout on
SQL> declare
  2    x xmltype;
  3    new_x xmltype;
  4  begin
  5    with emp as ( select 123 empno, 'O''Brien' ename from dual )
  6    select
  7      xmlelement("blah",
  8        xmlforest(e.empno as "empid",
  9                  e.ename as "name")
 10        )
 11    into x
 12    from emp e;
 13
 14    dbms_output.put_line(x.getClobVal());
 15    new_x := xmltype(dbms_xmlgen.convert(x.getClobVal(), dbms_xmlgen.ENTITY_DECODE));
 16    dbms_output.put_line(new_x.getClobVal());
 17
 18  end;
 19  /
<blah><empid>123</empid><name>O&apos;Brien</name></blah>
<blah><empid>123</empid><name>O'Brien</name></blah>

PL/SQL procedure successfully completed.


Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

THANK YOU!! YOU SENT ME IN THE RIGHT DIRECTION!!

Michael Kemp, January 24, 2018 - 5:15 pm UTC

Thank you Connor.

You sent me in the right direction.

Here is my final solution (Statement #2):

https://livesql.oracle.com/apex/livesql/file/content_F585VFOS8X30ZZO1VMV5JYNGA.html

select dbms_xmlgen.convert(xmlagg(xmlelement(e, rpad(' ', 5)
|| '||'
|| ' ''123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354x'' -- '
|| lpad(trim(to_char(q1.f1)), 3, '0')
|| '.'
|| chr(10))).extract('//text()').getclobval(), 1) f1
from (select level f1
from dual
connect by level < 51) q1
/

Connor McDonald
January 25, 2018 - 1:48 am UTC

Nice work

More to Explore

Design

New to good database design? Check out Chris Saxon's full fundamentals class.