zoukankan      html  css  js  c++  java
  • null类型的字段加1

    很高兴今天学到了一种新方法。

    数据库中字段类型为Long ,值可能为null,也可能是某一数。因此对该字段数值进行 +1操作时需要判断该值是null还是数值。

    同时实现更新操作。具体如下:

    update content set hits =
              case when hits is null
              then 1
              else hits+1
              end
              where id= 123456

    还有另外一种方式,先判断值,若为null则另其为0,否则是本身数组,对该数值进行+1操作。

    update content set hits =

    (
           select case when hits is null

           then 0

           else hits

           end

           + 1

          from content 

          where id = 123456
    ) where id = 123456

    这种方式去掉select关键字效果也是相同的:

    update content set hits = 

               case when hits is null

               then 0

               else hits

               end

               + 1
               where id = 123456

    这样就实现了对null字段照样+1.

  • 相关阅读:
    不等高cell的搭建(一)
    重复点击主界面(TabBar)按钮刷新界面--点击状态栏回到顶部
    如何学习新框架(保存图片到相册)
    上下拉刷新
    MVVM框架思想
    不等高cell的tableView界面搭建
    UITabBarController底层实现
    封装业务类
    RSS阅读器
    构造队列
  • 原文地址:https://www.cnblogs.com/yunyunde/p/4184609.html
Copyright © 2011-2022 走看看