sql 换行符处理

 

There are times when you need to insert some special characters such as “newline”,”tab”
etc as values into a field. Usually every one tries with ‘\n’ or ‘\t’, in vain.
we can do this by using the ASCII value of the character. The steps are very simple.

if you want to insert a special character find the ASCII value of that character like ‘ 9 for tab’, ‘ 12 for new line’ etc.
you can find the lists of characters with its ASCII values at
http://awesomesql.wordpress.com/2009/08/10/ascii-character-set-table.

Once this is done, concatenate your string with the character of that particular ASCII value as
‘my string and’+ char(12)+’someting’

this will be

my string and

something


an examle is as shown below

INSERT INTO TABLES( FIELDS)

下面这句非常关键
SELECT ‘hello’+char(9)+’:'+char(12)+’this is a new line’

this will be stored in the table as
-------------------------

    hello    :

    this is a new line

--------------------------

in the above example I inserted a tab after hello and a new line after ‘:’

you can similarly use
下面是特殊字符所在的accii码

new line = char(12)

space = char(32)

horizontal tab = char(9)

carriage return = char(15)

vertical tab = char(13)

end of text = char(3)


sqlite 换行符号的处理
插入时: 'A' || X'0A' || 'B' 字符串A,B之间用 换行符连接起来

java 取出时 已经自动变成\n, 可以自动换行了。
当然也可以接去掉, 看个人需要
select replace(os_version, x'0a','\n') from tb_scan_host, 可以转换

 

附:editplus 替代特殊字符

 

There are times when you need to insert some special characters such as “newline”,”tab”
etc as values into a field. Usually every one tries with ‘\n’ or ‘\t’, in vain.
we can do this by using the ASCII value of the character. The steps are very simple.

if you want to insert a special character find the ASCII value of that character like ‘ 9 for tab’, ‘ 12 for new line’ etc.
you can find the lists of characters with its ASCII values at
http://awesomesql.wordpress.com/2009/08/10/ascii-character-set-table.

Once this is done, concatenate your string with the character of that particular ASCII value as
‘my string and’+ char(12)+’someting’

this will be

my string and

something


an examle is as shown below

INSERT INTO TABLES( FIELDS)

下面这句非常关键
SELECT ‘hello’+char(9)+’:'+char(12)+’this is a new line’

this will be stored in the table as
-------------------------

    hello    :

    this is a new line

--------------------------

in the above example I inserted a tab after hello and a new line after ‘:’

you can similarly use
下面是特殊字符所在的accii码

new line = char(12)

space = char(32)

horizontal tab = char(9)

carriage return = char(15)

vertical tab = char(13)

end of text = char(3)


sqlite 换行符号的处理
插入时: 'A' || X'0A' || 'B' 字符串A,B之间用 换行符连接起来

java 取出时 已经自动变成\n, 可以自动换行了。
当然也可以接去掉, 看个人需要
select replace(os_version, x'0a','\n') from tb_scan_host, 可以转换

附:editplus 替代特殊字符

3. 替代特殊字符 \r\n \r\n\r\n
    3.1 清除\r\n\r\n
    查找: (.)+(\\r\\n\\r\\n)(.)*
    替换: \1' || X'0A' || X'0A' || '\3

 

    3.2 清除\r\n
    查找: ([^\\n])+(\\r\\n)([^\\r])*
    替换: \1' || X'0A' || '\3

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值