首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > oracle >

如何查找字符串中的多个人名,在数据库中对应的邮箱

2012-10-20 
怎么查找字符串中的多个人名,在数据库中对应的邮箱?从jsp中接受到的参数类似:“张三李四王五马六”数据库

怎么查找字符串中的多个人名,在数据库中对应的邮箱?
从jsp中接受到的参数类似:“张三;李四;王五;马六”

数据库中有2个字段,一个是人名,一个是邮箱。怎么写SQL才能把这些人的邮箱取出来?

[解决办法]

SQL code
SQL> with u(name,email) as(  2  select '張三','1@163.com' from dual  3  union all select '李四','2@163.com' from dual  4  union all select '王五','3@163.com' from dual  5  union all select '馬六','4@163.com' from dual  6  )  7  select wm_concat(u.email) from u,(  8  select regexp_substr('張三;李四;王五;馬六', '[^;]+',1,rownum) name from dual  9      connect by rownum<=length('張三;李四;王五;馬六')-length(replace('張三;李四;王五;馬六', ';', ''))+1) t 10  where u.name=t.name;WM_CONCAT(U.EMAIL)                                                              --------------------------------------------1@163.com,2@163.com,3@163.com,4@163.com
[解决办法]
。。。 按分号分隔你传进来的字符串。。。。 还要怎么解释。。。。

探讨
能大概解释下这2句吗?知道是正则表达式,但是思路看不懂


SQL code

select regexp_substr('張三;李四;王五;馬六', '[^;]+',1,rownum) name from dual
9 connect by rownum<=length('張三;李四;王五;馬六')-length(replace('張三;李四;王五;馬六', ';', ……

热点排行