SELECT TRIM(USER.PNAME || ' ' || USER.FNAME) AS "NAME"
Concat VARCHAR2 fields in Oracle DB
-
20-07-2023 - |
Domanda
For an SQL view I want to concat two fiels of varchar2-type
ROW | PNAME | FNAME
1 | JOHN | DOE
2 | (null) | DOE
3 | JOHN | (null)
4 | (null) | (null)
The result I want to get is
1 | 'JOHN DOE'
2 | 'DOE'
3 | 'JOHN'
4 | (null)
The best I could achieve so for looks like this
SELECT USER.PNAME || ' ' || USER.FNAME AS "NAME"
But this gives me the following result
1 | 'JOHN DOE'
2 | ' DOE'
3 | 'JOHN '
4 | ' '
I know why I get this result, but how could I get rid of the obsolete blank that I don't want to have in the result?
I am using Oracle 11g.
Soluzione
Altri suggerimenti
You can use:
SELECT DECODE(USER.PNAME,"",USER.PNAME,USER.PNAME || ' ') || USER.FNAME AS "NAME"
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow