oracle 拼接資料

來源:互聯網
上載者:User

標籤:記錄   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 拼接資料

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.