Oracle中的关键词

嗯……碰到哪个写哪个,做个整理

1、decode

select decode(sex,1,'男','女') from student

意思就是在Student表中 sex下为1 则sex是男,否则就是女

2、时间格式

select to_char(date,'yyyy-MM-dd hh24:mi:ss') date from Time

查询的时间要以这种格式输出

3、isEquals用于动态拼接sql

                 -----------转自https://www.cnblogs.com/warrior4236/p/5978752.html

如下实例:

如果status的状态为0,则更新attribute1;状态为1,则更新attribute2;

状态为2,则更新attribute3

<update   id="topup.doEffect" parameterClass="java.util.HashMap">
update  cis_customer  set  code_id  = #codeId# ,
<isEqual property="status" compareValue="0" prepend=",">  
            attribute1=#attribute1#</isEqual>  
        <isEqual property="status" compareValue="1" prepend=",">  
            attribute2=#attribute2#</isEqual>  
        <isEqual property="status" compareValue="2" prepend=",">  
            attribute3=#attribute3#</isEqual>
where  id = #id#
</update>

4、isNotEmpty

                ----------------转自https://www.cnblogs.com/warrior4236/p/5978752.html

如下实例:

查询cis_customer这张表,如果属性aaa不为空,则将条件aaa=#aaa#拼接;

如果bbb不为空,则将条件bbb=#bbb#拼接;如果属性ccc不为空,则将条件ccc=#ccc#拼接;

<select  id="topup.querySuccessCount" parameterClass="java.util.HashMap">
 2      select id,name from cis_customer where 1=1
 3      <isNotEmpty  property="aaa"  prepend="and">  
 4                  aaa=#aaa#
 5   </isNotEmpty  >  
 6   <isNotEmpty  property="bbb"  prepend="and">  
 7                  bbb=#bbb#
 8    </isNotEmpty  >  
 9    <isNotEmpty  property="ccc" prepend="and">  
10                 ccc=#ccc#
11   </isNotEmpty  >
12   </select>  

5、order by

这个order by 是个比较基础的词,昨天在看的时候发现了个我不太熟悉的点,然后随手整理下来了。

select * from student order by age

这句是将Student表按age大小排序,没有写如何排序,则默认为升序(ASC)

select * from student order by age desc

这句是将Student表按照age大小排序,并且是按降序排序(DESC)

  • ASC表示按升序排序
  • DESC表示按降序排序

 上面的都是一个字段排序,下面来个俩的

select * from student order by age ,name desc

这句是将Student表先按照第一个age字段排序,如果在age字段升序排序不分先后的情况下,用name进行二次排序,此处name用的是降序

select * from st_password order by upper(password)

这句是将st_password 表下的password按升序排序并且区分大小写 。

select * from student order by age nulls last

这句呢就是讲Student表下按age进行升序排序,并且将值为null的放在后面

NULLS FIRST在非NULL值之前放置NULL值,NULLS LAST在非NULL值之后放置NULL

 

--------------------先写这几个,更新ing

  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值