mysql_query 嵌套,在querydsl中调用mysql嵌套/内部函数

I need to run the following query in QueryDsl Native MySQL.

SELECT cast(json_unquote(JSON_EXTRACT(vendor_master,'$.vendor.currency')) as char) as currency FROM vendor;

The above query has 3 mysql functions which are nested such as cast,json_unquote and json_extract.

In QueryDsl, I have created separate Expression for each function as shown in the below code.

SimpleExpression exp1=Expressions.simpleTemplate(String.class,"json_extract({0},{1})",vendor.vendorMaster,"$.vendor.currency");

SimpleExpression exp2=Expressions.simpleTemplate(String.class,"json_unquote({0})",exp2);

SimpleExpression exp3=Expressions.simpleTemplate(String.class,"cast({0} as char) as currency",exp3);

List tuples=sqlQueryFactory.select(exp3).from(vendor).fetch();

I have to create more number of expressions as much as no of functions. Is it possible to call more than one function in single expression in order to reduce complexity?

解决方案

I found the answer for the question.

SimpleExpression exp=Expressions.simpleTemplate(String.class,"cast(json_unquote(json_extract({0},{1})) as char) as currency",vendor.vendorMaster,"$.vendor.currency");

List tuples=sqlQueryFactory.select(exp).from(vendor).fetch();

Thanks for your response.

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值