Jan 04 2007

PL/SQL concatenating names

Posted at 9:00 am under Pl/SQL

To concat first name, middle name, and last name in Pl/SQL:

first_name_field||’ ‘||middle_name_field||’ ‘||last_name_field

 

To concat first name, middle initial, and last name do the following:

first_name_field||’ ‘||substr(middle_name_field,1,1)||’ ‘||last_name_field

 

If you want a period(.) and space after the folks who do have a middle initial/name and if you want no space or period if they do not have a middle initial/name:

first_name_field||’ ‘||
decode(substr(middle_name_field,1,1),null,”,substr(middle_name_field,1,1)||’. ‘)||last_name_field

 

I wrote that decode function all by myself without having to search on google or look at a pl/sql programming book. WOOT!

 

 

tags: , , , , , ,

2 responses so far

2 Responses to “PL/SQL concatenating names”

  1. Matton 04 Jan 2007 at 2:49 pm 1

    Looks good! Once suggestion for a bit more efficiency you could leave out the substr in the first section of the decode. As so:

    first_name||’ ‘||decode(middle_name_field,null,”,substr(middle_name_field,1,1)||’. ‘)||last_name_field

  2. mandymagon 05 Jan 2007 at 6:10 am 2

    Thanks bork! Yes I can see how the extra substr is not necessary.. :)

Trackback URI | Comments RSS

Leave a Reply