我使用shell脚本在sqlplus中执行导出
阀芯:
SET echo off
SET linesize 32767
SET LONG 1000
SET LONGCHUNKSIZE 1000
SET wrap off
SET heading off
SET colsep ';'
SET pagesize 0
SET feed off
SET termout off
SET trimspool off
SELECT
AUTO_SEQ.nextval as ROW_ID,
..
..
结果:
29419987;FOR_IMPORT;1000 ;KR 19 F 65 73 ;KR 19 F 65 73, 47001, 47000 ;SANTA MARTA ;Cargado por EIM en 03-MAY-17 ;KR 19 F 65 73, 47001, 47000 ;KR 19 F 65 73, 47001, 47000 ;KR 19 F 65 73, 47001, 47000 ;MAGDALENA ; ;COLOMBIA; ; ; ; ; ;Y;N;Y
结果在数据之前和/或之后有很多空白,所以我的问题是如何删除它们?
提前致谢。
答案 0 :(得分:1)
抓住自己当前版本的SQL Plus,你会很高兴
SQL> set markup csv on
SQL> select * from scott.emp;
"EMPNO","ENAME","JOB","MGR","HIREDATE","SAL","COMM","DEPTNO"
7369,"SMITH","CLERK",7902,"17-DEC-80",800,,20
7499,"ALLEN","SALESMAN",7698,"20-FEB-81",1600,300,30
7521,"WARD","SALESMAN",7698,"22-FEB-81",1250,500,30
7566,"JONES","MANAGER",7839,"02-APR-81",2975,,20
7654,"MARTIN","SALESMAN",7698,"28-SEP-81",1250,1400,30
7698,"BLAKE","MANAGER",7839,"01-MAY-81",2850,,30
7782,"CLARK","MANAGER",7839,"09-JUN-81",2450,,10
7788,"SCOTT","ANALYST",7566,"09-DEC-82",3000,,20
7839,"KING","PRESIDENT",,"17-NOV-81",5000,,10
7844,"TURNER","SALESMAN",7698,"08-SEP-81",1500,,30
7876,"ADAMS","CLERK",7788,"12-JAN-83",1100,,20
7900,"JAMES","CLERK",7698,"03-DEC-81",950,,30
7902,"FORD","ANALYST",7566,"03-DEC-81",3000,,20
7934,"MILLER","CLERK",7782,"23-JAN-82",1300,,10
答案 1 :(得分:0)
设置colsep
不会停止在列中输出结果,这意味着每行中的值仍然填充到相同的长度。我会忘记colsep
,而是将值与分隔符连接起来:
SELECT
AUTO_SEQ.nextval
||';'|| column1
||';'|| column2
...
||';'|| columnN
FROM
...
它提供单个列表达式,没有添加额外的空格。
你可能需要将字符串值sin双引号括起来,如果它们本身可以包含分隔符(虽然这在某种程度上取决于谁将使用它),并且你也可以将它们连接起来。您还应该明确地将日期格式化为字符串等,如果您还没有。