Oracle、Mysql 动态创建sql语句
MYSQL:
@Query(value = "select * from project_demand where project_id=?1 and if(?2!='',demand_id in (select demand_id from demand_user where user_id=?2),1=1)",nativeQuery = true) if(?2!='',demand_id in (select demand_id from demand_user where user_id=?2),1=1),就是生成动态SQL的方法,利用MYSQL的if函数和我们传递的参数去进行判断,然后获取SQL语句
Oracle:
DECODE(VALUE,IF1,THEN1,IF2,THEN2,IF2,THEN2,..,ELSE) 表示如果value等于if1时,DECODE函数的结果返回then1,...,如果不等于任何一个if值,则返回else。
相关推荐
CoderToy 2020-11-16
wangshuangbao 2020-11-13
苏康申 2020-11-13
要啥自行车一把梭 2020-11-12
vitasfly 2020-11-12
emmm00 2020-11-17
王艺强 2020-11-17
ribavnu 2020-11-16
bianruifeng 2020-11-16
vivenwan 2020-11-13
moyekongling 2020-11-13
云中舞步 2020-11-12
aydh 2020-11-12
kuwoyinlehe 2020-11-12
minerk 2020-11-12
jazywoo在路上 2020-11-11
敏敏张 2020-11-11
世樹 2020-11-11