oracle,跨多个可选字段(名字、中间名、姓氏)搜索

wf82jlnq  于 2021-07-24  发布在  Java
关注(0)|答案(1)|浏览(306)

我需要用一个搜索词搜索一个人的名字(分为3个字段)。
到目前为止我有这个代码:

SELECT * FROM "EMPLOYEES" WHERE (lower(first_name || middle_name || last_name) LIKE '%johnsmith%');

但这只在用户搜索一个或两个相邻的名称时有效。我想也能搜索 first_name + last_name . 我知道我可以分开做 OR 但是有没有别的办法 middle_name 可选?

ljo96ir5

ljo96ir51#

with names(first_name,middle_name,last_name)
    as(select 'John','','Doe' from dual
    union
    select 'Jane','Mary','Doe' from dual
    union
    select 'John','','Smith' from dual
    union
    select 'George','Smith','Michael' from dual
    union
    select 'John','Lee','Smith' from dual
    )
    select *
    from names
    where  lower(first_name||middle_name||last_name) like '%john%smith%'

FIRST_ MIDDL LAST_NA
------ ----- -------
John   Lee   Smith
John         Smith

相关问题