sql plus output is not coming in proper CSV format if we use the colsep ,

怎甘沉沦 提交于 2021-02-08 10:25:21

问题


The issue i am facing is that even the data in the CSV file also getting separated if the value consists of , (comma)

I am using shell script connect to oracle using the sql plus and spooling the data in the CSV file

In the CSV the colsep , (comma) is working fine to separate columns but the data also getting separated.

for example if the value of the company name is (Southern textiles,LICO ) In that case even SOuttheren textiles is in one column and LICO is moving to another column and thee remaining data is getting changed since the comma value separated.

Please help me in the below code i have used in my script is

set feedback off trimspool on;
set pagesize 50000
set serveroutput on
set underline off
set termout off
set feedback off
set colsep " , "
set HEADING ON
set tab off
set trimspool on
set linesize 2000
set trimout on;
column company_name format a10

回答1:


set colsep " , "

It is best not to surround the separator with spaces, because those spaces should be seen as part of the field by the parser (see RFC 4180).

If your fields contain , another separator (like ; or |) could be used, but the proper way is to surround those fields with " (probably a parameter to the generator). If the field itself has a " inside it should be escaped with another ".




回答2:


SQLPlus has CSV formatting. Just do

Set markup csv on



来源:https://stackoverflow.com/questions/61407396/sql-plus-output-is-not-coming-in-proper-csv-format-if-we-use-the-colsep

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!