[英]sql separators (DB2 but ORACLE can be too)
I need help with separators in sql.我需要有关 sql 中分隔符的帮助。 I'm working on DB2 but Oracle is also good.
我正在研究 DB2,但 Oracle 也不错。
I need to build query where I've got data in format: aaa.bbb.ccc.ddd@domain.com
where 'aaa', 'bbb', 'ccc', 'ddd' got not constant length.我需要在我有格式数据的地方构建查询:
aaa.bbb.ccc.ddd@domain.com
其中“aaa”、“bbb”、“ccc”、“ddd”的长度不是恒定的。 Query should return bbb and ddd.查询应返回 bbb 和 ddd。 In DB2 I can cut '@domain.com' which takes me really long line.
在 DB2 中,我可以删除“@domain.com”,这需要我排很长的队。 Rest I have no idea how to move.
休息我不知道如何移动。 I tried with SUBSTR but nothing has work like it should nad my queries are super long.
我尝试使用 SUBSTR,但没有任何工作可以像它应该 nad 我的查询超长一样。
I need query not block.我需要查询而不是阻止。 EXAMPLE: data in column:
示例:列中的数据:
John.W.Smith.JWS1@domain.com
Alexia.Nova.Alnov@domain.com
Martha.Heart.Martha2@domain.com
etc.等等。
In general I need to get data from between 1st and 2nd separator .
一般来说,我需要从 1st 和 2nd separator 之间获取数据
.
and the one which is in front of @
.和
@
前面的那个。
I'm sure someone will have some clever REGEX way of doing it, but this is one way to do it.我相信有人会有一些聪明的 REGEX 方法来做这件事,但这是一种方法。
with test as
( select 'John.W.Smith.JWS1@domain.com' col1 from dual union all
select 'Alexia.Nova.Alnov@domain.com' from dual union all
select 'Martha.Heart.Martha2@domain.com' from dual
)
select col1
, substr( col1, 1, dot_one-1 ) f1
, substr( col1, dot_one+1, dot_two - dot_one -1 ) f2
, no_domain
, substr( no_domain, dot_before_at+1 ) f3
from
(
select col1
,instr( col1, '@', -1 ) at_pos
,instr( col1, '.',1,1) dot_one
,instr( col1, '.',1,2) dot_two
,substr( col1, 1, instr(col1, '@', -1 )-1) no_domain
,instr( substr( col1, 1, instr( col1, '@', -1 ) -1 ) , '.', -1 ) dot_before_at
from test
)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.