sql-結果集運算符-正則式函數

UNION:相當於並運算符,合併兩個結構相同的結果集(兩個結果集可以來自兩個結構相同的不同的表)

select * from student 
where sclass ='97001'
union
select * from studnet
where sage=24;

UNION ALL :與union想比,不會去重,會把兩個都符合的結果打印兩遍

intersect :相當於集合的叫運算,只返回兩個參與運算結果集合中相同的記錄

select * from student 
where sclass ='97001'
intersect 			--相當於交運算
select * from studnet
where sage=24;

minus:相當於集合的減運算,只返回在一個檢索結果中存在,另一個檢索結果中國不存在的記錄

select * from student 
where sclass ='97001'
minus 			--相當於減運算
select * from studnet
where sage=24;

正則式函數(JavaSE 6.0 編程指南中有相關介紹,通用)

REFGEXP_LIKE(<表達式>,<正則式>):判斷表達式是否與指定模式相匹配
REFGEXP_REPLACE(<要替換的字符串>,<正則式>,<用來替換的串>):返回替換後的字符串

drop table student;

create table student
(
sno char(5),
sname varchar2(20),
sage number(2),
sclass char(5)
); 

insert into student values('10001','Tom',24,'97001');
insert into student values('10002','Lili',20,'97002');
insert into student values('10003','Jerry',22,'s7001');
insert into student values('10004','Anti',21,'97002');
insert into student values('10005','John',null,'s7002');
commit;

select * from student;

select sclass from student		--代表5個長度的數字字符串(\d代表數字,{5}代表5位)
where REGEXP_LIKE(sclass,'\d{5}');  

--替換
select REGEXP_REPLACE('aaaa12sd455d656','\d+','#')	--對爲數字替換成#
from dual;	

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章