注意:返回数量为0时函数返回值为false,返回数量为非零值时为true。

Java函数:

boolean hasSameServiceCode(@Param("oldDepotCd") String oldDepotCd,@Param("newDepotCd") String newDepotCd);

XML代码:

    <select id="hasSameServiceCode" resultType="java.lang.Boolean">
select (case when count(*)=1 then 1 else 0 end) as cnt from (
select distinct s.service_code
from depot d inner join service_carrier_mapping s
on d.carrier_code=s.handling_carrier_code
where exists (select null from DEPOT where depot_code=#{oldDepotCd})
and exists (select null from DEPOT where depot_code=#{newDepotCd})
and d.depot_code in (#{oldDepotCd},#{newDepotCd}) )
</select>

取值:

cnt=1,返回true

cnt=0,返回false

注意,如果直接写select count(*) from XXX,因为会有0,1, >1三种情况,如果是0,返回值是false,这个没有争议;如果是1,返回值为true;如果是>1,返回值也为true。非零值都是true,这个是我实测了的,并不像网文 https://blog.csdn.net/qq_39039017/article/details/80700002 所说的只有1返回true,0和大于1的值都返回false。

像我上面的业务,只能在返回1时返回真,返回0或者其它值都得返回假,这就需要用case语句来转化一下。

--2020-04-07--

最新文章

  1. [Android Pro] ScrollView嵌套RecyclerView时滑动出现的卡顿
  2. html局部打印
  3. Spring任务调度器之Task的使用
  4. (转)Hibernate事务管理
  5. Mac添加bash alias
  6. JDBC-java访问数据库
  7. freeCodeCamp:Factorialize a Number
  8. lstm的debug模式下编译不行貌似
  9. Collection Views and Building Custom Layouts-备
  10. 类似QtiPlot的veusz,sigmaplot,pymol
  11. Python爬虫小白---(二)爬虫基础--Selenium PhantomJS
  12. 浅谈 HTML5plus 开发移动应用
  13. c#枚举位运算操作
  14. golang 安装tensorflow
  15. vue 饿了么项目笔记
  16. (转)适用微信小程序的table表格(带隔行变色)
  17. 关于JSON call 的一个小问题
  18. [No000014D]chrome console 调试 引入 jquery等外部库
  19. You Don&#39;t Know JS: Scope &amp; Closures (第3章: 函数 vs 块作用域)
  20. 利用WordPress REST API 开发微信小程序从入门到放弃

热门文章

  1. PyTorch 学习
  2. ECS7天实践进阶训练营Day1:使用阿里云ECS,快速搭建、管理VuePress静态网站
  3. MyBatisPlus性能分析插件,条件构造器,代码自动生成器详解
  4. 【API进阶之路】帮公司省下20万调研费!如何巧用情感分析API实现用户偏好调研
  5. [leetcode/lintcode 题解] 有效回文 II &#183; Valid Palindrome II
  6. scss @mixin &amp; @include
  7. LeetCode 115.不同的子序列 详解
  8. windows安装cnpm步骤
  9. CSS动画实例:Loading加载动画效果(一)
  10. Android studio 在项目里配置签名 + cmd命令安装apk在测试机