Read Using SQL Snippets before using any of this site's code or techniques on your own systems.

Columns to String

Setup

Run the code on this page in SQL*Plus to create the sample tables, data, etc. used by the examples in this section.

Be sure to read Using SQL Snippets before executing any of these setup steps.

create table t
(
  key   varchar2(10) ,
  val_1 varchar2(6)  ,
  val_2 varchar2(6)  ,
  val_3 varchar2(6)  ,
  note  varchar2(25)
);

insert into t values ( 'String 1' , 'a' , null, null , 'One NOT NULL, Two NULL'    );
insert into t values ( 'String 2' , null, 'b' , null , 'One NOT NULL, Two NULL'    );
insert into t values ( 'String 3' , null, null, 'c'  , 'One NOT NULL, Two NULL'    );
insert into t values ( 'String 4' , 'a' , 'b' , null , 'Two NOT NULL, One NULL'    );
insert into t values ( 'String 5' , 'a' , 'b' , 'c'  , 'Three NOT NULL, Zero NULL' );
insert into t values ( 'String 6' , null, null, null , 'Zero NOT NULL, Three NULL' );

commit;

column xml_string format a50