有一个表:
create table t1 (col1 varchar(1024));
col1
-------------------------------
1;1;1;1;1 ->需要的数据
123;2;3;22;2 ->需要的数据
I;love;computer;very;much ->需要的数据
;;;; ->不需要的数据
1;;;; ->不需要的数据
1;;2;; ->不需要的数据
NULL ->不需要的数据
123;2;3;22;2;3r43;44 ->不需要的数据
ilove csdn ->不需要的数据
This is a little ->不需要的数据
1111111 ->不需要的数据
怎么写一个SQL把 字段里面 只含有4个分号 ; 的非空字符串(注意不能多于4个,也不能少于4个,用;被分隔的字符串也不能为空)提取出来 ,或者有没有这样的函数来实现???
谢谢各位!!!
------解决方案--------------------
自己写个函数,大致类似下面
v_length := LENGTH(v_field);
WHILE (v_start <= v_length) LOOP
v_index := INSTR(v_field, ',', v_start);
IF v_index = 0 THEN
v_word := SUBSTR(v_field, v_start);
v_start := v_length + 1;
ELSE
v_word := SUBSTR(v_field, v_start, v_index - v_start);
v_start := v_index + 1;
END IF;
END LOOP;
------解决方案--------------------
SELECT * FROM t1 WHERE REGEXP_LIKE(col1,'^([^;]+(;)){4}([^;]+)$');
------解决方案--------------------
--使用正则表达式
Select * From Test1
where case when regexp_like (col1,'\w+;\w+;\w+;\w+') then 1 else 0 end =1;
------解决方案--------------------
…… 你确定是在用Oracle数据库吗?
------解决方案--------------------

好歹也两级专家了,发帖也太马虎了吧。什么数据库都不说下
------解决方案--------------------
length(col1)-length(replace(col1,';',''))=4 and length(col1)=length(replace(col1,';;','')可解决
------解决方案--------------------
能否帮忙用: REGEXP_INSTR 来实现
SELECT * FROM t1 WHERE REGEXP_INSTR(col1,'^([^;]+(;)){4}([^;]+)$') > 0;