Want to split value based on space if no space want to show null in second column [message #631775] |
Mon, 19 January 2015 11:11 |
|
cplusplus1
Messages: 58 Registered: October 2012 Location: usa
|
Member |
|
|
I have the following Query: the first part is the name and second part after space is their Title, sometimes there is no title just name, in those cases to show a null in column two. Can you please kindly adivse how to handle in those scenarios as well with one query.
select ltrim(rtrim(SUBSTR('Perez-Pascual MD',1,instr('Perez-Pascual MD',' ')-1))) as Last_name,
ltrim(rtrim(SUBSTR('Perez-Pascual MD', INSTR('Perez-Pascual MD',' ', -1, 1)+1))) as Doctor_Title
from Dual;
select ltrim(rtrim(SUBSTR('Perez-Pascual MD',1,instr('Perez-Pascual MD',' ')-1))) as Last_name,
ltrim(rtrim(SUBSTR('Perez-Pascual', INSTR('Perez-Pascual',' ', -1, 1)+1))) as Doctor_Title
from Dual;
Thanks a lot for the helpful info.
|
|
|
|
|
|
|