我知道,在某些编程语言中,如果您执行以下操作:
'This is on first line \n This is on second line'
然后它会像这样正确显示:
This is on first line
This is on second line
当我在SQLite数据库中连接一个字符串时
SELECT *, [FIELD1] || '\n' || [FIELD2] from TABLE
(其中[FIELD1] =这是在第一行 [FIELD2] =这是在第二行)
它显示如下:
This is on first line \n This is on second line
是否有理由不正确显示\ n字符?
答案 0 :(得分:24)
SQL没有反斜杠转义。
您可以直接在查询中生成字符串中的换行符:
SELECT [Field1] || '
' || [Field2] FROM MyTable
或使用blob literal:
SELECT [Field1] || x'0a' || [Field2] FROM MyTable
或使用char function:
SELECT [Field1] || char(10) || [Field2] FROM MyTable
答案 1 :(得分:0)
尝试char(13)
(如果您想在Windows记事本中看到它)。
select col || char(13) from mytable