最近在做統計查詢時,遇到乙個數值0.2查詢出來卻顯示.2的問題,於是查詢原因,發現oracle對數值0.n轉換成char型別的時候會自動忽略前面的0。本文將通過實際案例講解怎麼解決這種問題。
實際專案中乙個統計示例sql:
select r.xqid,r.yf,r.roomid,r.floorid,r.flowid,r.campus_key,r.roombh,listagg(to_char(r.class_name),',') within group(order by r.class_name) class_name,
listagg(to_char(r.fdymc || '(' || r.fdykf || ')'),',') within group(order by r.class_name) fdymc,
r.kfcs,r.xnxqmc,r.depname,r.xykf from (select xqid,yf,roomid,floorid,flowid,campus_key,yxid,yxmc,roombh,class_name,fdymc,fdyid,kfcs,fdykf,xq.xnxqmc, depname,depid,
case when xypm=1 then xykf+0.4 when xypm = 2 then xykf+0.3 when xypm=3 then xykf+0.2 when xypm=4 then xykf+0.1 else xykf end as xykf
from (
select xqid,yf,roomid,floorid,flowid,campus_key,yxid,yxmc,roombh,wm_concat(class_name) class_name ,fdymc,fdyid,sum(kfcs)as kfcs ,(kfcs*0.05) as fdykf,fjs*0.01 as xykf,qszs, fjs,depid,depname,
round(fjs/qszs,5) as bjgzb,rank() over(partition by yf order by round(fjs/qszs,5) desc )as xypm
from (
select t.xqid,t.yf,t.roomid,t.floorid,t.flowid,t.campus_key,t.kfcs,t2.yxid,t2.yxmc,t1.roombh,t1.class_name,t2.fdymc,t2.fdyid,cy.fjs,cy1.qszs,d.department_name as depname,d.department_key as depid
from (select yf,roomid,floorid,flowid,campus_key,xqid,count(*) kfcs from zhxg_gy_rcgl_hnsxy_wsjcdj t left join zhxg_xtsz_jxz t1 on t.jxzid = t1.pkid where dj='2' group by xqid,yf,roomid,floorid,flowid,campus_key) t
left join v_zhxg_gy_gyjbxx_cyfp t1 on t.roomid = t1."roomid"
left join wp_kdb_department d on d.department_key = t1.fjszdepid
left join ( select r.depid,count(*) fjs from
(select t.depid,t.roomid from zhxg_gy_gyjbxx_cyfp t
where t.roomid in (select w.roomid from zhxg_gy_rcgl_hnsxy_wsjcdj w group by w.roomid)
group by t.depid,t.roomid) r group by r.depid
) cy on t1."depid" = cy.depid
left join ( select r.depid,count(*) qszs from
(select t.depid,t.roomid from zhxg_gy_gyjbxx_cyfp t group by t.depid,t.roomid) r group by r.depid
) cy1 on t1."depid" = cy1.depid
left join v_zhxg_xgdw_fdybj t2 on t1."bjid" = t2.bjid
where t1."stuid" is not null and t1."depid" = d.department_key
group by t.xqid,t.yf,t.roomid,t.floorid,t.flowid,t.campus_key,t.kfcs,t2.yxid,t2.yxmc,t1.roombh,t1.class_name,t2.fdymc,t2.fdyid,cy.fjs,cy1.qszs,d.department_key,d.department_name
) group by xqid,yf,roomid,floorid,flowid,campus_key,yxid,yxmc,roombh,fdymc,fdyid,fjs,qszs,kfcs,depid,depname
) left join zhxg_xtsz_xqxx xq on xqid = xq.pkid) r group by r.xqid,r.yf,r.roomid,r.floorid,r.flowid,r.campus_key,r.roombh,r.kfcs,r.xnxqmc,r.xykf,r.depname
;
查詢結果:可以看到0.2被顯示成了.2。
下面講解怎麼解決這種問題,使其正常輸出展示在頁面。
使用case..when判斷是否以''.''開頭,如果是則在前面加乙個0,否則直接輸出
使用decode結合substr判斷第乙個字元是否是".",如果是則在前面拼接乙個"0",否則直接輸出
踩坑筆記之Integer數值比較
很多東西,表面上看起來挺簡單,實際上別有洞天,一不小心就是乙個坑。記錄一下昨天遇到的integer數值比較所遇到的 奇葩bug 1.問題場景 先看如下一段 if activity.gettotalcounts activity.getparticipationcounts activity.gett...
Oracle 踩坑記錄
在 做datax的一些功能測試,需要oracle,中間遇到的一些檔案進行記錄 安裝過程 現 ins 30014 谷歌有人說設定本機host,沒有成功。最後將本機網路關閉,該檔案得到解決,安裝過程最後進度條部分會略慢 很久沒有使用oracle,裡面的各種概念已經忘記。可以cmd 然後 sqlplus ...
oracle踩的那些坑
1.oracle日誌滿溢 公司測試環境忽然莫名其妙用不了了,檢查後發現是oracle監聽關閉了,嘗試啟動監聽,很慢,等待很久 反覆啟動後才啟動成功。然而成功後又提示連線超時。漫長的檢查後,發現是oracle的日誌檔案沒有清理,導致日誌檔案滿溢,oracle監聽自動關閉 卡頓。解決方法很簡單,直接關閉...