SQLITE Select 结果转化为字符串

SQLITE Select results into a string

我正在寻找一种方法 return 将 SQLite 查询的结果作为单个字符串用于内部触发器。

类似于 Python 的 'somestring'.join() 方法。

Table: foo
id    |    name
1     |     "foo"
2     |     "bar"
3     |     "bro"

然后select语句:

MAGIC_STRING_CONCAT_FUNCTION(SELECT id FROM foo,",");

到return “1,2,3”

您正在查找 group_concat 函数:

group_concat((SELECT id FROM foo), ",");

以下为the description of the function group_concat from the documentation

group_concat(X) group_concat(X,Y)

The group_concat() function returns a string which is the concatenation of all non-NULL values of X. If parameter Y is present then it is used as the separator between instances of X. A comma (",") is used as the separator if Y is omitted. The order of the concatenated elements is arbitrary.