SQLITE 将结果选择为字符串 [英] SQLITE Select results into a string

查看:26
本文介绍了SQLITE 将结果选择为字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am looking for a method to return the results of an SQLite query as a single string for use in an internal trigger.

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

Something like Python's 'somestring'.join() method.

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

然后是一个选择语句:

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

返回1,2,3"

推荐答案

您正在寻找 group_concat 函数:

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

以下是文档中group_concat函数的说明:

The following is the description of the function group_concat from the documentation:

group_concat(X) group_concat(X,Y)

group_concat() 函数返回一个字符串,它是X 的所有非 NULL 值的串联.如果参数 Y 存在然后它被用作 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.

这篇关于SQLITE 将结果选择为字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆