SQL Plus将表转换为CSV文件问题
我在将 Oracle 数据库中的表字段转换为 CSV 文件时遇到无法解决的问题。我有一个 varchar2(4000) 列,用户在其中输入他们的评论。有时,用户从其他程序(例如 MS Word)复制并粘贴文本,因此,许多额外信息被粘贴到字段中,例如回车符和换行符。该字段中也可能有大量文本。由于某种原因,即使我去掉了回车符和换行符,CSV 文件仍然显示 CR 和 LF,这导致当我在 Excel 中打开 CSV 文件时数据被分成两行。以下是我针对本专栏的代码。有人可以帮我弄清楚为什么会发生这种情况以及是否有办法解决这个问题?非常感谢任何帮助。谢谢。
SET RECSEP OFF
SET TRIMOUT ON
SET TRIMSPOOL ON
SET TERMOUT OFF
SET TERM OFF
SET ECHO OFF
SET VERIFY OFF
SET HEAD OFF
SET PAGESIZE 0
SET LINESIZE 3000
SET COLSEP '|'
SET FEEDBACK OFF
SET WRAP ON
spool 'C:\Temp\data.csv'
SELECT REPLACE (REPLACE (TRIM(COMMENTS), chr(13),''), chr(10), '')
FROM T_COMMENT;
SPOOL OFF
I'm having a problem that I can't figure out while converting a table field in an Oracle database to a CSV file. I have a column of varchar2(4000) where users enter their comments. Sometimes the users copy and paste text from other programs such as MS Word therefore, a lot of extra information is pasted into the field such as carriage returns and line feeds. There can also be large amount of text in this field. For some reason, even though I get rid of the carriage returns and line feeds, the CSV file still shows a CR and LF which causes the data to be separated into two rows when I open the CSV file in Excel. Below is my code for just this column. Can someone help me figure out why this is happening and if there is a way to fix the issue? Any help is much appreciated. Thanks.
SET RECSEP OFF
SET TRIMOUT ON
SET TRIMSPOOL ON
SET TERMOUT OFF
SET TERM OFF
SET ECHO OFF
SET VERIFY OFF
SET HEAD OFF
SET PAGESIZE 0
SET LINESIZE 3000
SET COLSEP '|'
SET FEEDBACK OFF
SET WRAP ON
spool 'C:\Temp\data.csv'
SELECT REPLACE (REPLACE (TRIM(COMMENTS), chr(13),''), chr(10), '')
FROM T_COMMENT;
SPOOL OFF
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
通常,如果 CSV 文件的数据中包含逗号或回车符,则该字段会用双引号引起来,以标识该字段跨越多行。
我不确定其他角色的情况,但这是我看到的处理方式。
Typically, if a CSV file has commas or carriage-returns in the data then the field is double-quoted to identify that the field spans multiple lines.
I'm not sure about the other characters, but this is the way I've seen this dealt with.