Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
832 views
in Technique[技术] by (71.8m points)

newline - New Line character in SQLite concatenate

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

'This is on first line 
 This is on second line'

Then it will display properly like this:

This is on first line
This is on second line

When I concatenate a string in a SQLite database

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

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

it displays as such:

This is on first line 
 This is on second line

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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

or use a blob literal:

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

or use the char function:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...