標籤:記錄 rac 個數 sel art 資料 log date nbsp
這幾天遇到Ajax取值時的資料傳遞是String類型,拿到字串後就進行資料分割,所以需要對資料庫查詢到的資料進行拼接,
以下就是資料拼接的語句
select replace(wm_concat(Trim (to_char(round(天數,1),‘0.9‘))),‘,‘,‘-‘) from(
SELECT
MIN(logi_date)
over(PARTITION BY logi_pi
ORDER BY logi_date rows
BETWEEN 1 following AND 2 following) - logi_date 天數
FROM t_bu_transport_d_move m
where logi_pi = ‘A4071005‘
order by logi_date);
其中
1:wm_concat的用法為“行轉列”,意思就是把某一列的全部資料放在同一行裡,:這就拿到所有需要的列的資料的拼接;
2:replace的用法是替換,replace(‘字串‘,‘,‘,‘-‘),這一句的意思是把‘字串’的‘,’替換為‘-’;
3:Trim的用法是去除字串前後的空格,Trim(‘字串‘);
4:to_char的用法是轉為字元類型,to_char(‘number‘),‘0.9‘))),這一句的意思是把number轉換為字元類型,‘0.9‘是樣式,且樣式都用帶‘9‘的字元表示;
5:round是對數位取值,四捨五入;
6:over函數指定了分析函數工作的資料視窗的大小,這個資料視窗大小可能會隨著行的變化而變化,例如:
over(order by salary)按照salary排序進行累計,order by是個預設的開窗函數
over(partition by deptno) 按照部門分區
over(order by salary range between 50 preceding and 150 following)每行對應的資料視窗是之前行幅度值不超過50,之後行幅度值不超過150的資料記錄
over(order by salary rows between 50 perceding and 150 following)前50行,後150行
over(order by salary rows between unbounded preceding and unbounded following)所有行
over(order by salary range between unbounded preceding and unbounded following)所有行
7:rows BETWEEN 1 following AND 2 following:1在這裡不是從第1條記錄開始的意思,而是指目前記錄的前一條記錄,意思是下一條資料減上條資料;
oracle 拼接資料