查询时尽可能少用*查询,查询效率很较高
条件逻辑
case when 表达式 then 数据值
when 表达式 then 数据值
else 数据值
end as 字段名
例子:
select ename,
sal,
case
when sal <=2000 then '过低'
when sal >=4000 then '过高'
else 'OK'
END as status
from emp;
限制返回行数
select * from (select rownum as sn,emp.* from emp where rownum<=2)
where sn=2;
随机返回数据
查询语句执行顺序
1.select
2.rownum
3.order by
例子:
select empno,ename from
(select empno,ename from emp order by dbms_random.value())
where rownum<=3;
模糊查询-通配符、转义字符
_,%,\