Spacing. [message #234945] |
Thu, 03 May 2007 09:20 |
lamnguyen14
Messages: 119 Registered: March 2007 Location: Virginia
|
Senior Member |
|
|
Hi all.
I have a select statement like this:
select rpad(ID_CODE,5,' ')||BR||NAME from prospect;
Output:
12436#Lolita
12439Kimberly
12430#Louise
12431#Wayne
12432#Erin
12433Sheila
Because the columm BR [varchar2(1)] has some null value rows and I want the output leave a space for BR if it is null.
For example, I would like the output leave a space between 12439 & Kimberly
and 12433 & Sheila.
Would you please to show me how to do? I would appreaciate that.
|
|
|
|
Re: Spacing. [message #234948 is a reply to message #234945] |
Thu, 03 May 2007 09:30 |
|
Maaher
Messages: 7065 Registered: December 2001
|
Senior Member |
|
|
NVL does the trick:
SQL> WITH yourtable AS
2 (
3 SELECT 12436 id_code, '#' BR, 'Lolita' thename FROM dual UNION ALL
4 SELECT 12439 id_code, NULL BR, 'Kimberly' thename FROM dual UNION ALL
5 SELECT 12430 id_code, '#' BR, 'Louise' thename FROM dual UNION ALL
6 SELECT 12431 id_code, '#' BR, 'Wayne' thename FROM dual UNION ALL
7 SELECT 12432 id_code, '#' BR, 'Erin' thename FROM dual UNION ALL
8 SELECT 12433 id_code, NULL BR, 'Sheila' thename FROM dual
9 )
10 SELECT id_code||NVL(br,' ')||thename yourstring
11 FROM yourtable
12 /
YOURSTRING
-------------------------------------------------
12436#Lolita
12439 Kimberly
12430#Louise
12431#Wayne
12432#Erin
12433 Sheila
6 rows selected.
MHE
|
|
|
|