`
dadi520
  • 浏览: 139838 次
  • 性别: Icon_minigender_1
  • 来自: 重庆
社区版块
存档分类
最新评论

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

 

 

 

 

 

 

分享到:
评论

相关推荐

    MySQL数据中很多换行符和回车符的解决方法

    发现问题 今天一大早客户给我打电话:“小陈儿,昨晚我往数据库导了几十万条数据,然后在...如:库中数据为:“换行符\n换行符\n换行符”,然后在界面通过如下SQL查询,那自然是搜不到咯! SELECT * from `LOL` where

    浅谈mysql数据库中的换行符与textarea中的换行符

    # data为textarea获取的数据, 其中包括换行符`\r\n`, 以下是过渡处理 data = data.replace(‘\r\n’, ‘\n’) # 或 data = data.replace(‘\r\n’, chr(10)) 以上这篇浅谈mysql数据库中的换行符与textarea中的换行...

    Oracle除去数据中的换行符以免读取出现问题

    很多数据存进数据库后,可能需要将整条数据取出,并用特殊符号分割,而且整条...换行符 chr(10) 回车符 chr(13) 您可能感兴趣的文章:Oracle中serveroutput参数一次设置永久保存方法oracle导出sql语句的结果集和保存执

    matlab代码输入如何换行符-utl_map_counties_within_one_state_choropleth_map:在一个州Ch

    matlab代码输入如何换行符utl_map_counties_within_one_state_choropleth_map 在一个州Choropleth地图内绘制县区的地图。 关键字:sas sql join合并大数据分析宏oracle teradata mysql sas社区stackoverflow ...

    mysql针对字段中换行符\r\n进行查询和删除

    1、应用场景:mysql中某个数据字段包含换行符,导致前台解析json时报错  “Uncaught SyntaxError: Unexpected token in JSON at position 333”; 2、针对以上可将数据粘贴进notepad++查看,其中问题部分json如下所...

    精通SQL--结构化查询语言详解

    第1章 数据库与sql基础 1 1.1 数据库的基本概念 1 1.1.1 数据库的由来 1 1.1.2 数据库系统的概念 3 1.2 数据库系统的结构、组成及工作流程 3 1.2.1 数据库的体系结构 3 1.2.2 数据库系统的组成 4 1.2.3 ...

    Microsoft SQL Server 2005 Express Edition SP3

    由于未在 Windows 中完全配置 Microsoft 分布式事务处理协调器 (MS DTC),因此,应用程序可能无法在分布式事务中登记 SQL Server Express 资源。此问题会影响使用分布式事务的链接服务器、分布式查询以及远程存储...

    通过Java正则表达式去掉SQL代码中回车换行和多余空格

    刚才在写一个代码工具,遇到SQL换行和多余空格的问题,导致处理很困难,于是写了一个正则式,搞定了,特分享下方便需要的朋友

    sql-formatter:用于格式化sql语句的轻量级php类。 处理自动缩进和语法突出显示

    除了语法高亮显示之外,它还可以自动缩进并添加换行符。历史我发现自己不得不一直调试自动生成SQL语句,并希望找到一种方法来轻松输出格式化HTML,而不必包含巨大的库或将其复制并粘贴到在线格式化程序中。 我最初...

    matlab代码输入如何换行符-utl_sort_transpose_and_summarize_in_one_proc_v2:在一个过程中对

    matlab代码输入如何换行符utl_sort_transpose_and_summarize_in_one_proc_v2 在一个过程中对转置和汇总进行排序。 关键字:sas sql join合并大数据分析宏oracle teradata mysql sas社区stackoverflow statistics人工...

    SQL性能优化

     实际大部分应用中是不会产生重复的记录,推荐采用UNION ALL操作符替代UNION,因为UNION ALL操作只是简单的将两个结果合并后就返回。  Exists 示例:当有 A、B 两个结果集,当结果集 B 很大时,A 较小时,适用 ...

    达梦数据库_SQL语言手册

    达梦数据库_SQL语言手册.pdf 数据库快照定义语句 数据库快照删除语句 第章数据查询语句和全文检索语句 单表查询 简单查询 带条件查询 集函数 情况表达式 连接查询 子查询 标量子查询 表子查询 派生表子...

    sql-formatter:用于格式化sql语句的轻量级php类。处理自动缩进和语法突出显示

    除了语法高亮显示之外,它还可以自动缩进并添加换行符。 历史 这个包是来自一个分支。这是原始“历史记录”部分所说的内容: 我发现自己不得不一直调试自动生成SQL语句,并希望找到一种方法来轻松输出格式化HTML,而...

    精通SQL 结构化查询语言详解

    《精通SQ:结构化查询语言详解》全面讲解SQL语言,提供317个典型应用,读者可以随查随用,针对SQL Server和Oracle进行讲解,很有代表性。 全书共包括大小实例317个,突出了速学速查的特色。《精通SQ:结构化查询语言...

    2009达内SQL学习笔记

    大多数SQL实现支持以下类型的函数: 文本处理, 算术运算, 日期和时间, 数值处理。 Null:空值 空值当成无穷大处理,所有空值参与的运算皆为空。 空值与空值并不相等,因为空值不能直接运算。 如:prod_price...

    精通sql结构化查询语句

    1.5 SQL开发环境 1.5.1 SQL环境介绍 1.5.2 SQL的层次结构 1.5.3 SQL环境中的对象 1.5.4 SQL环境中的程序系统 1.6 SQL语句基础 1.6.1 SQL常量 1.6.2 SQL表达式 1.6.3 SQL数据类型 1.6.4 注释符 1.6.5 批处理 1.6.6 ...

    Oracle SQL高级编程(资深Oracle专家力作,OakTable团队推荐)--随书源代码

    作者通过总结各自多年的软件开发和教学培训经验,与大家分享了掌握Oracle SQL所独有的丰富功能的技巧所在,内容涵盖SQL执行、联结、集合、分析函数、子句、事务处理等多个方面。读者可以学习到以下几个方面的技巧:...

    SQL语法大全

    SQL语法大全 SQL语法大全 1. ASP与Access数据库连接: dim conn,mdbfile mdbfile=server.mappath("数据库名称.mdb") set conn=server.createobject("adodb.connection") conn.open "driver={microsoft access ...

    SQLtoCSV:SQLtoCSV - 运行 SQL 并生成完全限定的 CSV 的 Windows 工具

    如果数据单元格包含逗号和换行符,则默认情况下导出工具会忽略它。 有可以解决这个问题,但它仍然存在问题。 换行符仍然可以留下损坏的无法使用的 CSV 记录。待办事项命令行版本支持 MySQL 等任意 SQL 解决方案保存...

Global site tag (gtag.js) - Google Analytics