首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

sql转hql 求解!该如何解决

2012-09-06 
sql转hql 求解!!!SQl为:select temp.aa as 日期,temp.bb as DC,temp.cc as 品类,temp.ee as 品牌,temp.ff

sql转hql 求解!!!
SQl为:

select temp.aa as 日期,temp.bb as DC,temp.cc as 品类,temp.ee as 品牌,temp.ff as "收货能力(箱)",temp.gg as "收货能力(体积)",temp.hh as 已预约箱数,temp.jj as 已预约体积 from 
(
select (select trunc(sysdate) from users where rownum =1) aa,dc.dc_name bb,dd.category cc,dd.brand ee,dd.average_receive_capacity ff,dd.average_receive_volume gg,
nvl((select sum(o.box_quantity) from log2_appoint_carrier_order o 
left join log2_appoint_carrier c on c.id=o.appoint_carrier_id 
left join log_base_organization org on org.id=c.receiver_id 
inner join log_receive_ndc_order ndc on ndc.purchasecode=o.purchase_code and ndc.confirmcode=o.confirm_code and nvl(ndc.selfordercode,'a')=nvl(o.self_build_code,'a')
where trunc(o.appoint_receive_date)=trunc(sysdate) and org.org_name=dc.dc_name and o.status='APPROVED' and ndc.categorys=dd.category),0) hh,
nvl((select sum(o.volume) from log2_appoint_carrier_order o 
left join log2_appoint_carrier c on c.id=o.appoint_carrier_id 
left join log_base_organization org on org.id=c.receiver_id 
inner join log_receive_ndc_order ndc on ndc.purchasecode=o.purchase_code and ndc.confirmcode=o.confirm_code and nvl(ndc.selfordercode,'a')=nvl(o.self_build_code,'a')
where trunc(o.appoint_receive_date)=trunc(sysdate) and org.org_name=dc.dc_name and o.status='APPROVED' and ndc.categorys=dd.category),0) jj
from log_base_dc_infodetail dd
inner join log_base_dc_info dc on dc.id=dd.dcinfo_id and dc.dc_type='NDC' 
where dd.ability_start_time<trunc(sysdate) and dd.ability_end_time>trunc(sysdate) and dd.status='ACTIVE' 
union all 
select (select trunc(sysdate+1) from users where rownum <=1) aa,dc.dc_name bb,dd.category cc,dd.brand ee,dd.average_receive_capacity ff,dd.average_receive_volume gg,
nvl((select sum(o.box_quantity) from log2_appoint_carrier_order o 
left join log2_appoint_carrier c on c.id=o.appoint_carrier_id 
left join log_base_organization org on org.id=c.receiver_id 
inner join log_receive_ndc_order ndc on ndc.purchasecode=o.purchase_code and ndc.confirmcode=o.confirm_code and nvl(ndc.selfordercode,'a')=nvl(o.self_build_code,'a')
where trunc(o.appoint_receive_date)=trunc(sysdate+1) and org.org_name=dc.dc_name and o.status='APPROVED' and ndc.categorys=dd.category),0) hh,
nvl((select sum(o.volume) from log2_appoint_carrier_order o 
left join log2_appoint_carrier c on c.id=o.appoint_carrier_id 
left join log_base_organization org on org.id=c.receiver_id 
inner join log_receive_ndc_order ndc on ndc.purchasecode=o.purchase_code and ndc.confirmcode=o.confirm_code and nvl(ndc.selfordercode,'a')=nvl(o.self_build_code,'a')
where trunc(o.appoint_receive_date)=trunc(sysdate+1) and org.org_name=dc.dc_name and o.status='APPROVED' and ndc.categorys=dd.category),0) jj
from log_base_dc_infodetail dd
inner join log_base_dc_info dc on dc.id=dd.dcinfo_id and dc.dc_type='NDC' 
where dd.ability_start_time<trunc(sysdate+1) and dd.ability_end_time>trunc(sysdate+1) and dd.status='ACTIVE' 
  )temp 
group by temp.aa,temp.bb,temp.cc,temp.ee,temp.ff,temp.gg,temp.hh,temp.jj order by temp.aa asc

下面是转换为HQL的语句:

SELECT temp.aa as businessDate,temp.bb as dcName,temp.cc as category,temp.ee as brand,temp.ff as averageReceiveCapacity,temp.gg as averageReceiveVolume,temp.hh as boxQuantity,temp.jj as volume 
  FROM (SELECT 
  (SELECT trunc(sysdate) from User where rownum=1) as aa,dc.name as bb,dd.category as cc,dd.brand as ee,dd.averageReceiveCapacity as ff,dd.averageReceiveVolume as gg,
nvl((SELECT sum(o.boxQuantity) from AppointmentCarrierOrder o,NDCOrder ndc 
left join o.appointmentCarrier c 
left join c.receiver org where trunc(o.appointReceiveDate)=trunc(sysdate) and org.name=dc.name and o.status='APPROVED' 


and ndc.category=dd.category and ndc.purchaseCode=o.purchaseCode and ndc.confirmCode=o.confirmCode 
and nvl(ndc.selfOrderCode,'a')=nvl(o.selfBuildCode,'a')),0) as hh,
nvl((SELECT sum(o.volume) from log2_appoint_carrier_order o,NDCOrder ndc 
left join o.appointmentCarrier c 
left join c.receiver org where trunc(o.appointReceiveDate)=trunc(sysdate) and org.name=dc.name and o.status='APPROVED' 
and ndc.category=dd.category and ndc.purchaseCode=o.purchaseCode and ndc.confirmCode=o.confirmCode 
and nvl(ndc.selfOrderCode,'a')=nvl(o.selfBuildCode,'a')),0) as jj from DCInfoDetail dd,DCInfo dc 
where (trunc(sysdate) between dd.abilityStartDate and dd.abilityEndDate) and dd.status='ACTIVE' and dc.type='NDC'
) temp where 1=1
group by temp.aa,temp.bb,temp.cc,temp.ee,temp.ff,temp.gg,temp.hh,temp.jj order by temp.aa

其中 temp 为临时表  

异常信息为:
 org.hibernate.hql.ast.QuerySyntaxException: unexpected token: ( near line 2, column 46 
也就是上述HQL中的 
SELECT temp.aa as businessDate,temp.bb as dcName,temp.cc as category,temp.ee as brand,temp.ff as averageReceiveCapacity,temp.gg as averageReceiveVolume,temp.hh as boxQuantity,temp.jj as volume 
  FROM “(”这个括号 SELECT 
请各位高手指点迷津,是我HQL写错了,还是有不支持的语法

[解决办法]
你不要把 HQL 和 SQL 混为一谈好么?

HQL 肯定可以转换为 SQL,但这种转换只是单向的,SQL 并不一定都能转换为 HQL

热点排行