SQL 字符串连接在 SQLite 中不起作用

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3568779/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 07:19:32  来源:igfitidea点击:

String concatenation does not work in SQLite

sqlsqlitestringoperatorsconcatenation

提问by Ian Vink

I am trying to execute a SQlite replace function, but use another field in the function.

我正在尝试执行 SQlite 替换函数,但使用函数中的另一个字段。

select  locationname + '<p>' from location;

In this snip, the result is a list of 0s. I would have expected a string with the text from locationname and the '<p>'literals.

在这个片段中,结果是一个 0 列表。我本来希望有一个字符串,其中包含来自 locationname 和'<p>'文字的文本。

回答by codaddict

Try using ||in place of +

尝试使用||代替+

select  locationname || '<p>' from location;

From SQLite documentation:

来自SQLite 文档

The || operator is "concatenate" - it joins together the two strings of its operands.

|| 运算符是“连接” - 它将其操作数的两个字符串连接在一起。

回答by shamittomar

The ||operator is the concatenation in SQLite. Use this code:

||操作是在SQLite的级联。使用此代码:

select  locationname || '<p>' from location;

回答by Brian Burns

For comparison,

为了比较,

SQLite                      ||  
Oracle                      CONCAT(string1, string2) or ||
MySQL                       CONCAT(string1, string2, string3...) or || if PIPES_AS_CONCAT enabled
Postgres                    CONCAT(string1, string2, string3...) or ||
Microsoft SQL Server 2012+  CONCAT(string1, string2, string3...) or + 
Microsoft Access            +  

回答by quickdraw

for Visual Studio 2010, using the Data Sources designer or wizard, you're in trouble using || operator. Create a view in the sqlite db and create your data source(s) from that.

对于 Visual Studio 2010,使用数据源设计器或向导,您在使用 || 时遇到了麻烦 操作员。在 sqlite 数据库中创建一个视图并从中创建您的数据源。

See also this thread.

另请参阅此线程