oracle简单学习总结(二)――查询(二)

2014-11-24 13:01:56 · 作者: · 浏览: 1
KE
用于进行模式匹配
Select * from userInfor Where name like '张%'
IS [NOT] NULL
用于测试是否为空值
Select * from userInfor Where name is not null
ANY ,SOME
同列表或查询中的每一个值进行比较,测试是否有一个满足,前面必须使用的
运算符包括=、!=、>=、<=、>、<等
Select * from userInfor Where age>any(select age from userInfor where name='张三')
ALL
同列表或查询中的每一个值进行比较,测试是否所有的值都满足,前面必须使用的运算符包括=、!=、>=、<=、>、<等
Select*from userInfor Where
age
[NOT] EXISTS
测试是否子查询至少返回一行
Select name 用户,age from userInfor where exists(select age from userInfor where birthday>to_date('1986-02-08','yyyy:MM:dd'));
说明:1、BETWEEN:对于数值型或日期型数据,表示范围时用。下限在前,上限在后,不能颠倒。查询范围中包含上下限的值
2、LIKE:完成按通配符查找字符串的查询操作,该操作符适合于对数据进行模糊查询;%:代表0个或多个任意字符。_ :代表一个任意字符。
问题1:any , some ,all 区别
解答:
* Some:表示满足其中一个的意义,是用or串起来的比较从句。
sql: Select t.* from userInfor t Where t.age=some(select age from userInfor where sex=0);
\
理解:先执行:select age from userInfor where sex=0
再执行:select t.* from userInfor t Where t.age=26ort.age=12;
* Any:也表示满足其中一个的意义,也是用or串起来的比较从句,区别是any一般用在非“=”的比较关系中,这也很好理解,英文中的否定句中使用any肯定句中使用some,这一点是一样的。
sql: Select t.* from userInfor t Where t.age
\
理解:先执行:select age from userInfor where sex=0
再执行:select t.* from userInfor t Where t.age<26ort.age<12;
* All:表示满足其中所有的查询结果的含义,使用and串起来的比较从句。
sql:select t.* from userInfor t Where t.age
\
理解:先执行:select age from userInfor where sex=0
再执行:select t.* from userInfor t Where t.age<26 andt.age<12;
问题二:in , EXISTS的理解
解答:
*EXISTS
sql:Select name 用户,age from userInfor where exists(select age from userInfor where birthday>to_date('1986-02-08','yyyy:MM:dd'));
\
学习参考:
http://www.2cto.com/database/201210/159551. html
http://www.2cto.com/database/201210/159550.html