首先建立測試數據sql
-- Create table create table UF_PQJZB ( id INTEGER not null, requestid INTEGER, pqmc VARCHAR2(100), sszq INTEGER, sfyx INTEGER, formmodeid INTEGER, modedatacreater INTEGER, modedatacreatertype INTEGER, modedatacreatedate VARCHAR2(10), modedatacreatetime VARCHAR2(8), modedatamodifier INTEGER, modedatamodifydatetime VARCHAR2(100), modeuuid VARCHAR2(100), modelableid VARCHAR2(200), pqbm VARCHAR2(99), qdbls INTEGER, pqdd CLOB ) tablespace ECOLOGY pctfree 10 initrans 1 maxtrans 255 storage ( initial 64K next 1M minextents 1 maxextents unlimited ); -- Create/Recreate indexes create index UF_IND_1595982945177 on UF_PQJZB (MODEUUID) tablespace ECOLOGY pctfree 10 initrans 2 maxtrans 255 storage ( initial 64K next 1M minextents 1 maxextents unlimited ); -- Create/Recreate primary, unique and foreign key constraints alter table UF_PQJZB add primary key (ID) using index tablespace ECOLOGY pctfree 10 initrans 2 maxtrans 255 storage ( initial 64K next 1M minextents 1 maxextents unlimited );
插入數據dom
insert into uf_pqjzb (ID, AA) values (57, '5120,4940');
sql顯示函數
SELECT * FROM ( with t AS ( SELECT id,to_char(pqdd) AS aa from uf_pqjzb WHERE pqdd IS NOT NULL AND ID ='57' ) select ID,regexp_substr(aa, '[^,]+', 1, level) cc from t connect by level <= regexp_count(aa, '\,\') + 1 and aa = prior aa and prior dbms_random.value > 0 )
結果顯示測試
最後咱們能夠學一個行轉列函數ui
根據id合併spa
SELECT ID , LISTAGG(cc, ',') WITHIN GROUP (ORDER BY ID) FROM (SELECT * FROM ( with t AS ( SELECT id,to_char(pqdd) AS aa from uf_pqjzb WHERE pqdd IS NOT NULL AND ID ='57' ) select ID,regexp_substr(aa, '[^,]+', 1, level) cc from t connect by level <= regexp_count(aa, '\,\') + 1 and aa = prior aa and prior dbms_random.value > 0 )) GROUP BY ID;
結果code
好了,固然也能夠用WM_CONCAT函數regexp
可是必定要注意WM_CONCAT轉換爲是clob字段須要注意orm