Seventeen0084 2019-03-06 22:02 采纳率: 100%
浏览 2298
已结题

数据库的 if 语句怎么使用

####select * from article if( typeCode != null && typeCode != '')where TYPE_CODE like CONCAT("", #{typeCode},"%")
####if后括号为真时执行where,if后括号为假时只执行select * from article
 
####正确的写法应该是怎样的?

  • 写回答

6条回答 默认 最新

  • 攻城狮爱上程序猿 2019-03-07 08:55
    关注

    IF 表达式

    IF( expr1 , expr2 , expr3 )

    expr1 的值为 TRUE,则返回值为 expr2
    expr1 的值为FALSE,则返回值为 expr3

    你将if写在where后面,expr1换成你的判断条件,expr2换成你的查询条件,expr3换成1=1(如果expr1不成立,自行select * from 表名 where 1=1)
    望采纳!

    评论

报告相同问题?