3.过滤与排序

1.where语句

//查询编码号为十号的员工
select * from emp where deptno=10;

注意:字符串大小写敏感	时间格式敏感

//查询名叫KING的员工
select * from emp where name='KING';

//查询入职日期17-11-81的员工
select * from emp where hiredate='17-11月-81';
select * from emp where hiredate='1981-11-17';	//这个是错误的
oracle将'='两边都转成date格式来比较

 

2.修改日期格式
select * from v$nls_parameters;		//查询oracle系统参数
alter session|system set NLS_DATE_FORMAT="yyyy-mm-dd";
如果session,表时当前对象有效,退出无效,而system对整个数据库有效

 

3.比较运算符
操作符		含义
=		等于(不是==)
>		大于
>=		大于,等于
<		小于
<=		小于等于
<>		不等于(也可以是!=)

BETWEEN...	在两个值之间(包含边界)
AND		
IN(SET)		等于值列表中的一个
LIKE		模糊查询
IS NULL		空值

例子:
select * from emp where deptno<=10;
select * from emp where sal between 1000 and 2000;(注意:包括边界,小值在前)

4.非空查询:

语法:
不为空	列名	IS NOT NULL
为空	列名	IS NULL

5.逻辑运算

逻辑运算符
操作符		含义
AND		逻辑并
OR		逻辑或
NOT		逻辑否

示例:
select * from emp where comm is null and not(sal>1500);

select * from emp where comm is not null or sal>1500;

6.范围查询

示例:
基本工资大于1500但是小于3000的全部雇员
select * from emp where sal>1500 and sal<3000;

select * from emp where sal between 1500 and 3000;

select * from hiredate between '1-1月-1981' and '31-12月-1981';

7.模糊查询

"%":可以匹配任意长度的内容
"_":可以匹配一个长度的内容

select * from emp where ename like 's%';
select * from emp where ename like '____';
查询名字中含有下划线的员工(转义字符) escape后面加上转义字符
select * from emp where ename like '%_%' escape'\';

8.使用orderby排序

查询员工信息,按照月薪排序 默认升序
select * from emp oreder by sal;
order by 后面+列,表达式,别名,序号
select empno,ename,sal,sal*12 from emp order by sal*12 desc;

使用别名
select empno,ename,sal,sal*12 年薪 from emp order by 年薪 desc;
使用列数
select empno,ename,sal,sal*12 from emp order by 4 desc;

多列排序升序
(注意:这里deptno升序排列,排列完后,再对sal进行升序排列,即在同一个deptno的集合中再进行sal的排序)
select empno,ename,sal,sal*12 from emp order by deptno,sal;
多列排序降序(desc作用于离他最近的列)
select empno,ename,sal,sal*12 from emp order by deptno,sal desc;
规则:order by 作用于后面的所有列,先按照第一个列排序,再后面的列
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值