日期:2014-05-17  浏览次数:20707 次

存储过程有问题 没找出来
报错:Oracle00-918:未明确定义列的错误。
应该是字段名没有准确定义,或者有相同的字段名。但我找了好久 没找出来。用这个显示数据没问题,用这个来导出excel 就报那个错误了。



select a.empid,a.empname,i.factoryname,c.organizationname
  ,d.professionallevelname
  ,a.stufflevelname
  ,h.biXiuKC 
  ,k.CreditHoursTotal
  ,h.allduration
  ,h.lessonNum
  ,h.learnedHour
  ,h.learnedLesson
  ,h.biXiuTongG 
  ,h.passhour
  ,FLOOR(h.passhour/|| I_ScorHour ||) as learnScore
  ,h.learnedHour-h.allduration as allDurationSub
  ,h.learnedHour-k.CreditHoursTotal as CreditHoursSub
  ,h.biXiuChaYi 
  ,||I_Year|| as year,s.dutystatusname 


from employees a
left join userinfo e on a.empid=e.empid
inner join (select f.userid,f.year,count(f.lessoncode) as lessonNum,round(sum(g.duration)/60,1) as allduration
  ,nvl(sum(case when f.status in ('E','F','R') then g.duration end)/60,0) as learnedHour
  ,nvl(sum(case when f.status in ('E','F','R') then 1 end),0) as learnedLesson
  ,nvl(sum(case when f.passchk=1 or (g.mustexamchk=0 and f.degreepercent=100) then g.duration end)/60,0) 
  as passhour
  ,nvl(count(case when aa.abilitytypecode='E' then f.lessoncode end),0) as biXiuKC 
  ,nvl(count(case when f.status in ('E','F','R') and aa.abilitytypecode='E' then 1 end),0) as biXiuTongG  
  ,(count(f.lessoncode)- count(case when aa.abilitytypecode='E' then f.lessoncode end)) as biXiuChaYi
  from userlessons f
  left join lessons g on g.lessoncode=f.lessoncode
  inner join abilities cc on cc.abilityid=f.abilityid 
  inner join abilitytypes aa on aa.abilitytypecode=cc.abilitytypecode
  where f.year=''|| I_Year ||'' and f.planlessonchk=1  
  group by f.year,f.userid 
  ) h on h.userid =e.userid
left join positions b on b.positioncode=a.positioncode
left join organizations c on c.organizationcode=b.organizationcode
left join professionallevels d on a.professionallevelcode=d.professionallevelcode
left join factorys i on i.factorycode=a.factorycode
left join (select t.Year, t.ProfessionalLevelCode, sum(t.CreditHours) as CreditHoursTotal
  from ProfLevelCreditHours t
  group by t.Year, t.ProfessionalLevelCode) k on k.year=h.year and k.ProfessionalLevelCode=a.professionallevelcode
left join dutystatus s on s.dutystatuscode = a.dutystatuscode
where nvl(a.delchk,0)=0




------解决方案--------------------
SQL code

 ,FLOOR(h.passhour/|| I_ScorHour ||) as learnScore
 ,||I_Year|| as year,s.dutystatusname  
--改為下面試下(連接符你此處沒用到,為何要加入)
 ,FLOOR(h.passhour/ I_ScorHour ) as learnScore
 ,I_Year as year,s.dutystatusname

------解决方案--------------------
你看下哪個列存在於兩個表中,用表的前綴加列就可以了

還有count(..)本身是0或大於0,不需要nvl,不過此處不是問題