Foreword
Before encountered such a demand, there was no record, this time they caught up, simply record it.
本文个人拙见,若有出入,请指出——来自菜的颤抖
Scenes
A table of information stored in the container, a container a record, a table B stored in the instruction operation for the container, an instruction includes a plurality of number of the container, separated by semicolons ;
cut ( TCIU2347687;XUTR3546865
), the current demand is for the instruction has been table B containers, when querying table a to be filtered out.
- It is easy to think of
not in
, but separated by semicolons. - Secondly,
not like
however[Err] ORA-01427: 单行子查询返回多个行
, it expressedlike
behind only accept a single value fuzzy query.
It must be separated by semicolons recording, split into a separate record.
become:
achieve
Oracle can be used regexp_substr函数
to achieve, achieve cut above sql as:
select regexp_substr('TCIU2347687;XUTR3546865', '[^;]+', 1, level) JZXXH
from dual connect by level <= regexp_count('TCIU2347687;XUTR3546865', ';') + 1
In which regexp_substr
the parameters of meaning:
TCIU2347687;XUTR3546865
It represents the need to split the string matching (I am here just to make an example, under real circumstances be table columns).[^;]+
A typical regular expression, I cut a semicolon here, it is determined segmentation rules多个不是分号的字符
, therefore experiencing a semicolon will end, get a complete string.1
Starting position, the extreme left ( the Oracle subscript is 1 start )level
It represents the first of several matches.
In order to understand this point of view straight functions, such as the following statement:
select REGEXP_SUBSTR('aaa;bbb','[^;]+',1,1) AS STR FROM dual;
The result is that aaa
, if the second 2 becomes 1, is output bbb
.
Well, this part of the intention is clear, here it is to take out each cutting string, see above take level个
, and this level
is what is it, before this, look at the regexp_count(string, c)
function, which is actually very good understanding, returns string the number of c.
Then comes the level, which is a pseudo-column, and RowNum similar,
SELECT LEVEL FROM DUAL CONNECT BY LEVEL <=2;
So back to the original sql, also well understood.
At last
Sincerely, salute