NutzCN Logo
问答 关于在代码中取出sqls文件对应sql问题。
发布于 2816天前 作者 苍蓝猛兽 1488 次浏览 复制 上一个帖子 下一个帖子
标签:

sqls 文件内容

/*xxx*/
/*20110.query.max.database.alert.status*/
select @resourceid as resourceid,
       case
         when r.value is null or r.value = '' then
          '00'
         else
          r.value
       end as value
  from (select max(t1.lev) as value
          from resourcedba.$table t0, perfdba.alert_unclosed t1
         where t0.resourceid = t1.resourceid
           and t0.appsystemid = @resourceid
           and t1.ltime = @time
           and t1.lev is not null
           and t1.lev != '99') r

代码取出sql字符串

Sql sql = dao.sqls().create(sqlId);
sql.toString();

DEBUG后发现sql输出如下

select 'NULL' as resourceid,
case
when r.value is null or r.value = '' then
'00'
else
r.value
end as value
from (select max(t1.lev) as value
from resourcedba. t0, perfdba.alert_unclosed t1
where t0.resourceid = t1.resourceid
and t0.appsystemid = 'NULL'
and t1.ltime = 'NULL'
and t1.lev is not null
and t1.lev != '99') r

疑问

  1. 代码中获取到的sql与sqls文件中不一致。
  2. 使用sql.vars().set()和sql.setParam()替换表名和设置值是可行的。
  3. 在union all数量较多的情况下,无法满足sql拼接。
添加回复
请先登陆
回到顶部