####select * from article if( typeCode != null && typeCode != '')where TYPE_CODE like CONCAT("", #{typeCode},"%")
####if后括号为真时执行where,if后括号为假时只执行select * from article
####正确的写法应该是怎样的?
数据库的 if 语句怎么使用
- 写回答
- 好问题 0 提建议
- 追加酬金
- 关注问题
- 邀请回答
-
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)
望采纳!解决 1无用