SQLite中的换行符\ n串联 [英] New Line character \n in SQLite concatenate

查看:294
本文介绍了SQLite中的换行符\ n串联的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,以某种编程语言,如果您执行以下操作:

I know that, in some Programming language, if you do something like:

'This is on first line \n This is on second line'

然后它将正确显示如下:

Then it will display properly like this:

This is on first line
This is on second line

当我在SQLite数据库中连接字符串

When I concatenate a string in a SQLite database

SELECT *, [FIELD1] || '\n'  || [FIELD2] from TABLE

(其中[FIELD1] =这是第一行 [FIELD2] =这是第二行)

(where [FIELD1] = This is on first line [FIELD2] = This is on second line)

显示如下:

This is on first line \n This is on second line

是否存在无法正确显示\ n字符的原因?

Is there a reason that it isn't displaying the \n characters properly?

推荐答案

SQL没有反斜杠转义符.

SQL has no backslash escapes.

您可以通过在查询中直接编写换行符来在字符串中生成换行符:

You can generate a newline in a string by writing it directly in the query:

SELECT [Field1] || '
' || [Field2] FROM MyTable

或使用 blob文字:

SELECT [Field1] || x'0a' || [Field2] FROM MyTable

或使用 char函数:

SELECT [Field1] || char(10) || [Field2] FROM MyTable

这篇关于SQLite中的换行符\ n串联的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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