--条件比较 /* =,!=,<>,<,>,<=,>=, any,some,all is null,is not null between x and y in(list),not in(list) exists(sub-query) like _ ,%,escape ‘\‘ _\% escape ‘\’ */ --any some 只要满足其中的任何一个即可 SELECT E.ENAME ,E.JOB,E.SAL FROM EMP E WHERE E.SAL > ANY(1000,2000,3000) SELECT E.ENAME ,E.JOB,E.SAL FROM EMP E WHERE E.SAL > SOME(1000,2000,3000) --all 满足所有的 SELECT E.ENAME ,E.JOB,E.SAL FROM EMP E WHERE E.SAL < ALL(1000,2000,3000) SELECT E.ENAME ,E.JOB,E.SAL FROM EMP E WHERE E.SAL > ALL(1000,2000,3000) --判断是否为null不能用"=" SELECT E.* FROM EMP E WHERE E.COMM=NULL; --无数据 SELECT E.* FROM EMP E WHERE NULL=NULL --无数据 SELECT E.* FROM EMP E WHERE E.COMM IS NULL; SELECT E.* FROM EMP E WHERE E.COMM IS NOT NULL; --and=与、or=或、between and 在两者之间 SELECT T.* FROM T_THREE_KILLED T WHERE T.C_AGE >= 30 AND T.C_SEX = ‘男‘; SELECT T.* FROM T_THREE_KILLED T WHERE T.C_AGE = 30 OR T.C_AGE = 31; SELECT T.* FROM T_THREE_KILLED T WHERE T.C_AGE BETWEEN 27 AND 33; --IN EXISTS 的区别 --IN会遍历表表中所有数据与条件进行匹配,所有当子查询数据较多时使用IN会使查询效率较低 SELECT T.* FROM T_THREE_KILLED T WHERE T.C_AGE IN (SELECT R.C_AGE FROM T_THREE_KILLED R WHERE R.C_AGE BETWEEN 30 AND 33); --EXISTS 只要查询语句可以返回一条数据则整个表达式为true,适用于子查询数据较多 SELECT T.* FROM T_THREE_KILLED T WHERE EXISTS (SELECT R.C_AGE FROM T_THREE_KILLED R WHERE T.C_AGE = R.C_AGE AND R.C_AGE BETWEEN 30 AND 33); --LIKE模糊查询 ESCAPE 转义符 --在模式中,当转义符置于通配符之前时,该通配符就解释为普通字符 SELECT T.* FROM T_THREE_KILLED T WHERE T.C_NAME LIKE ‘%l\%%‘ escape(‘\‘); --ORACLE中的支持正则表达式的函数主要有下面四个: --REGEXP_LIKE :与LIKE的功能相似 --REGEXP_INSTR :与INSTR的功能相似 --REGEXP_SUBSTR :与SUBSTR的功能相似 --REGEXP_REPLACE :与REPLACE的功能相似
oracle between、 all、 in 和 exists的区别,模糊查询、4个正则表达式
原文:http://www.cnblogs.com/dyfbk/p/7643399.html