A 表 
no       serial_total              flg 
1        12,23,a4                   1 
2        a,b                        2 
3        b,c                        1 
4        c,d                        1 
5        d,e                        2 
要把a表中flg=1的数据,insert 到B 表 结果应该是这个样子的 
no       serial_no1  serial_no2  serial_no3  serial_no4  flg 
1        12            23           a4         null       1 
3         b            c            null       null       1 
4        c             d            null       null       1 如果用POSTGRE存储过程做更好,请赐教.

解决方案 »

  1.   


    insert into b (
      select
        no,
        substring_index(serial_total,',',1),
        substring_index(substring_index(concat(serial_total,',,,,'),',',2),',',-1),
        substring_index(substring_index(concat(serial_total,',,,,'),',',3),',',-1),
        substring_index(substring_index(concat(serial_total,',,,,'),',',4),',',-1),
        flg
      from a where flg=1
    )