Columns to String

This section presents techniques for taking values from multiple columns, like these,

VAL_1  VAL_2  VAL_3  NOTE
------ ------ ------ -------------------------
a                    One NOT NULL, Two NULL
       b             One NOT NULL, Two NULL
              c      One NOT NULL, Two NULL
a      b             Two NOT NULL, One NULL
a      b      c      Three NOT NULL, Zero NULL
                     Zero NOT NULL, Three NULL
 

and assembling them into a single, delimited string like this

STRING
--------------------
a
b
c
a,b
a,b,c
 

or this

STRING
--------------------
a,,
,b,
,,c
a,b,
a,b,c
,,
 

or this.

XML_STRING
--------------------------------------------------
<VAL_1>a</VAL_1>
<VAL_2>b</VAL_2>
<VAL_3>c</VAL_3>
<VAL_1>a</VAL_1><VAL_2>b</VAL_2>
<VAL_1>a</VAL_1><VAL_2>b</VAL_2><VAL_3>c</VAL_3>
 



Linking to SQL Snippets ™

To link to this page in Oracle Technology Network Forums or OraFAQ Forums cut and paste this code.

  • [url=http://www.sqlsnippets.com/en/topic-12118.html]SQL Snippets: SQL Techniques Tutorials - Columns to String[/url]

To link to this page in HTML documents or Blogger comments cut and paste this code.

  • <a href="http://www.sqlsnippets.com/en/topic-12118.html">SQL Snippets: SQL Techniques Tutorials - Columns to String</a>

To link to this page in other web sites use the following values.

  • Link Text : SQL Snippets: SQL Techniques Tutorials - Columns to String
  • URL (href): http://www.sqlsnippets.com/en/topic-12118.html