Sqlite Create new columns from column containing ;

前端 未结 2 616
孤街浪徒
孤街浪徒 2020-12-21 14:07

I have a database test.db with the first column containing 123456;abcdef;ghijk etc. Is it possible to split the data into its own colums?

<

相关标签:
2条回答
  • 2020-12-21 14:15

    You can split your rows into columns by:

    create table t1 as
    select substr(c1,0,instr(c1,';')) as column1, 
           substr(c1,instr(c1,';')+1,instr(c1,';')-1) as column2,
           substr(c1,instr(c1,';')+1+instr(substr(c1,instr(c1,';')+1),';')) as column3
    from table_test;
    

    where c1 is the column you are selecting from.

    0 讨论(0)
  • 2020-12-21 14:17

    There is no built-in SQLite function that can split strings like this.

    If your are using the SQLite C API or a wrapper like APSW, you could create your own function (C, APSW).

    If you want to do nothing more than a one-time conversion, export/import through a text file would be the simplest solution.

    0 讨论(0)
提交回复
热议问题