Kde…

Name Parser

There was a question asked on InformaticaDevelopement yahoo group about parsing names. I had a piece of code saved from asktom. I don’t know when I got it from asktom, but I know I got it from asktom. I just wanted to put it out here for reference. To parse names you would have to do the following.

SQL>create table name_test ( a varchar2(15) );
Table created.
SQL>insert into name_test values ( 'kirtan' );

1 row created.

SQL>insert into name_test values ( 'kirtan desai' );

1 row created.

SQL>insert into name_test values ( 'kirtan desai s' );

1 row created.

SQL>select substr( a||' ', 1, instr(a||' ' ' ')-1 ) first_name,
  2         substr( a||'  ', instr( a||'  '  ' ') +1, instr( a||'  '  ' ', 1, 2 )-instr(a||'  ' ' ')-1 ) last_name,
  3         rtrim(substr( a||'  ', instr( a||'  ' ' ',1,2)+1),' ') middle_init
  4   from name_test
  5  /

FIRST_NAME        LAST_NAME          MIDDLE_INIT
----------------  -----------------  -----------------
kirtan
kirtan  desai
kirtan  desai               s

hope this helps
Kirtan

hope this helpsKirtan

Leave a Reply