《Oracle查询优化改写》笔记第一章—单表查询 与 第二章 — 排序

查询所有行和列

    ---如果为空 ,则查询值为 0, 不同于nvl的是 coalesce 支持多个参数    

select coalesce(comm,0) from EMP_TEST t;  ---coalesce 

    ---取随机条数

   select empno ,ename from (select empno,ename from emp_test order by dbms_random.value()) 

    where rownum     <=3; 

-------------------------------------------------------------------------------------------------------------------------------

排序

    ---按子串排序

 select last_name,phone_number ,salary ,substr(t.phone_number ,-4) 

    from emp_test t 

    where rownum <=5 

    order by 4;

    

----TRANSLAE(expr,from_string,to_string)from_string 与 to_string 以字符为单位,对应字符一一替换。

    ----如果to_string 为空,则返回NULL

    ----如果to_string对应的位置没有字符,删除from_string中列出的字符将会被消掉

    select translate('ab 你好 bcadefg','asfdas','1234567') from dual;

    ----NULLS FIRST 空值在前,NULL LAST 空值在后

    select * from table_name order by column NULLS FIRST||LAST
----根据条件取不同列中的值来排序
select column_name from table_name 
order by  case when ??? and ??? then ? end ,column_name;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值