postgresql將多條記錄結果合並為一個字符串,並加入分隔符


將多行記錄轉化為一個字符串,用array_to_string內置函數即可!

select array_to_string(array(

    select distinct name from tab where 1=1

),'-->') as strs;

將一個字符串轉化為多行記錄,用regexp_splite_to_table即可!

select regexp_splite_to_table('asd,qwe,qeq,ere,fds,ert',',') as id;

分割之后再轉化為整數

select cast( regexp_splite_to_table('1,2,3,4,5,6',',') as integer) as id;


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM