SQL: parse the first, middle and last name from a fullname field

后端 未结 23 1692
粉色の甜心
粉色の甜心 2020-11-27 10:47

How do I parse the first, middle, and last name out of a fullname field with SQL?

I need to try to match up on names that are not a direct match on full name. I\'d

23条回答
  •  天命终不由人
    2020-11-27 11:24

    We of course all understand that there's no perfect way to solve this problem, but some solutions can get you farther than others.

    In particular, it's pretty easy to go beyond simple whitespace-splitters if you just have some lists of common prefixes (Mr, Dr, Mrs, etc.), infixes (von, de, del, etc.), suffixes (Jr, III, Sr, etc.) and so on. It's also helpful if you have some lists of common first names (in various languages/cultures, if your names are diverse) so that you can guess whether a word in the middle is likely to be part of the last name or not.

    BibTeX also implements some heuristics that get you part of the way there; they're encapsulated in the Text::BibTeX::Name perl module. Here's a quick code sample that does a reasonable job.

    use Text::BibTeX;
    use Text::BibTeX::Name;
    $name = "Dr. Mario Luis de Luigi Jr.";
    $name =~ s/^\s*([dm]rs?.?|miss)\s+//i;
    $dr=$1;
    $n=Text::BibTeX::Name->new($name);
    print join("\t", $dr, map "@{[ $n->part($_) ]}", qw(first von last jr)), "\n";
    

提交回复
热议问题