从Informatica中的名称字段中提取Title,FirstName,MiddleName和LastName

时间:2016-05-20 17:46:50

标签: informatica

我有一个名称字段的表,其中包含Title(可选),FirstName,MiddleName(可选)和LastName。所有记录都具有FirstName和LastName,但并非所有记录都具有Title或MiddleName。例如: Joey Tribbiani先生(没有中间名) 雷切尔凯伦格林(没有头衔) Monica E Geller女士(全部四个领域) Phoebe Buffay(没有标题或中间名)等等

我在桌子上的标题包括(先生,夫人,女士,女士,女士,或者Sra。)

在这种情况下,如何根据Informatica中的Title,FirstName,MiddleName和LastName分隔Name字段?

2 个答案:

答案 0 :(得分:0)

您可以使用informatica中的INSTR和SUBSTR函数来实现此目的

例如,您输入的NAME是Mr.Joey Tribbiani

注意:我假设先生和名字之间没有空格

TITLE:

IIF((INSTR(NAME, '',1))= 0,NULL, (SUBSTR(NAME,1,INSTR(NAME, '',1)-1)))

FIRSTNAME:

SUBSTR(NAME,INSTR(NAME,'。',1)+1,((INSTR(NAME,'',1)-1)-INSTR(NAME,'。',1)))

SUBSTR('Mr.Joey Tribbiani',INSTR('Mr.Joey Tribbiani','。',1)+1,((INSTR('Mr.Joey Tribbiani','',1)-1) - INSTR('Mr.Joey Tribbiani','。',1)))

最后一个名字:

SUBSTR(NAME,INSTR(NAME,'',1)+1)

SUBSTR('Mr.Joey Tribbiani',INSTR('Mr.Joey Tribbiani','',1)+1)

Oracle SQL语句供您参考

SELECT SUBSTR('Mr.Joey Tribbiani',1,INSTR('Mr.Joey Tribbiani','。',1)-1)FROM DUAL;

SELECT SUBSTR('Mr.Joey Tribbiani',INSTR('Mr.Joey Tribbiani','。',1)+1,((INSTR('Mr.Joey Tribbiani','',1)-1) -INSTR('Mr.Joey Tribbiani','。',1)))FROM DUAL;

SELECT SUBSTR('Mr.Joey Tribbiani',INSTR('Mr.Joey Tribbiani','',1)+1)FROM DUAL;

有关INSTR和SUBSTR

的详细说明,请查看以下链接

http://www.techonthenet.com/oracle/functions/instr.php http://www.techonthenet.com/oracle/functions/substr.php

此致 拉吉

答案 1 :(得分:0)

我假设每个单词之间只有一个空格。

我做了什么

  1. 检查标题是否存在并保存在变量中。
  2. 查找空格数并检查是否存在中间名。
  3. 根据上述条件派生titlefirst_namemiddle_namelast_name
  4. 像这样创建一个表达式转换。

    enter image description here

    以下是可变端口条件。

    v_title_exists

    IIF(
    SUBSTR(upper(v_FULL_NAME),1,3)='MR.' OR
    SUBSTR(upper(v_FULL_NAME),1,4)='MRS.' or
    SUBSTR(upper(v_FULL_NAME),1,3)='MS.' or
    SUBSTR(upper(v_FULL_NAME),1,2)='MS' or
    SUBSTR(upper(v_FULL_NAME),1,3)='SR.' or
    SUBSTR(upper(v_FULL_NAME),1,4)='SRA.'
    ,1,0)
    

    v_number_of_spaces

    length(v_FULL_NAME) - length(REPLACECHR(0,v_FULL_NAME,' ',''))
    

    v_middle_name_exists

    IIF(v_title_exists=1,
        IIF(v_number_of_spaces=3,1,0),
        IIF(v_number_of_spaces=2,1,0)
       )
    

    v_title_exists

    IIF(v_title_exists=1,
       substr(v_FULL_NAME,0,instr(v_FULL_NAME,' ',1,1) -1)
      , null
    )
    

    v_first_name

    IIF(v_title_exists=1,
           substr(
               v_FULL_NAME,
                instr(v_FULL_NAME,' ',1,1)+1, 
                 instr(v_FULL_NAME,' ',1,2)-instr(v_FULL_NAME,' ',1,1)
                          )
    ,
           substr(
               v_FULL_NAME,
                1, 
                 instr(v_FULL_NAME,' ',1,1)-1
                          )
    )
    

    v_middle_name

    IIF(v_middle_name_exists=1,
    IIF(v_title_exists=1,
           substr(
               v_FULL_NAME,
                instr(v_FULL_NAME,' ',1,2)+1, 
                 instr(v_FULL_NAME,' ',1,3)-instr(v_FULL_NAME,' ',1,2)
                          )
    ,
           substr(
               v_FULL_NAME,
                instr(v_FULL_NAME,' ',1,1)+1, 
                 instr(v_FULL_NAME,' ',1,2)-instr(v_FULL_NAME,' ',1,1)
                          )
    )
    ,
    null)
    

    v_last_name

    IIF(v_middle_name_exists=1,
    IIF(v_title_exists=1,
           substr(
               v_FULL_NAME,
                instr(v_FULL_NAME,' ',1,3), 
                 length(v_FULL_NAME)
                          )
    ,
           substr(
               v_FULL_NAME,
                instr(v_FULL_NAME,' ',1,2), 
                 length(v_FULL_NAME)
                          )
    )
    ,
    IIF(v_title_exists=1,
           substr(
               v_FULL_NAME,
                instr(v_FULL_NAME,' ',1,2), 
                 length(v_FULL_NAME)
                          )
    ,
           substr(
               v_FULL_NAME,
                instr(v_FULL_NAME,' ',1,1), 
                 length(v_FULL_NAME)
                          )
    )
    )