Sqlite 从包含的列中创建新列; [英] Sqlite Create new columns from column containing ;
问题描述
我有一个数据库 test.db
,第一列包含 123456;abcdef;ghijk
等.是否可以将数据拆分成自己的列?>
123456
永远不会改变长度.
abcdef
和 ghijk
改变长度,也可能不包含任何内容.
我尝试了下面的字符串,但我得到 ;
出现在 t2
或 t3
中,这取决于 abcdef 的长度
和 ghijk
.
select substr(column,1,6) AS "t1",substr(column,8,6) AS "t2",substr(column,15,10) AS "t3" test.db
是 ;
分隔符导致问题吗?
或者我可以将数据库输出到.sql
,格式化txt然后导入一个新的数据库?
没有 内置 SQLite 函数 可以像这样分割字符串.
如果您使用 SQLite C API 或像 APSW 这样的包装器,您可以创建自己的函数 (C、APSW).
如果您只想进行一次转换,那么通过文本文件导出/导入将是最简单的解决方案.
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?
123456
never changes length.
abcdef
and ghijk
change length and also may contain nothing.
I have tried the below string but i get the ;
appear in either t2
or t3
depending on the length of abcdef
and ghijk
.
select substr(column,1,6) AS "t1",
substr(column,8,6) AS "t2",
substr(column,15,10) AS "t3" test.db
Is the ;
seperator causing the issue?
Or can i output the database to .sql
, format the txt then import to a new database?
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.
这篇关于Sqlite 从包含的列中创建新列;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!