sqlplus,以1列导出查询,并且是无序的

标签 sql database oracle sqlplus

我正在使用脚本在 sqlplus 中执行查询,但是当我尝试导出到文件时遇到问题 我的 sqlplus 中有这个:

spool hits.csv

SET NEWPAGE NONE
SET PAGESIZE 0
SET SPACE 0
SET LINESIZE 100
SET ECHO OFF
SET FEEDBACK OFF
SET VERIFY OFF
SET HEADING OFF
SET MARKUP HTML OFF SPOOL OFF
SET TERMOUT OFF
SET TRIMOUT ON
SET TRIMSPOOL ON
SET COLSEP |
arraysize 15
set wrap off

select camp1, camp2, camp3, camp4 from table

spool off

但是当我读取文件时,类似于(截断查询的两列):

rows will be truncated

rows will be truncated

20131209|name12
20131209|name12
20131209|name12
20131209|name12
20131209|name12
20131209|name12

然后我增加线条大小,但如果我增加线条大小,请显示如下内容:

20131209|name12
|1                                                                                                                                                     
   |       86
20131209|name12                                                                                                                               
  |5                                                                                                                                                
 |        1
20131209|name12                                                                                                                               
  |2                                                                                                                                                
 |        9
 20131209|name12                                                                                                                               
 |3                                                                                                                                                
 |        5
 20131209|name12                                                                                                                               
 |6                                                                                                                                                
 |        1

我需要类似的东西:

20131209|name12|1|86
20131209|name12|5|1
20131209|name12|2|9
20131209|name12|3|5
20131209|name12|6|1

我读过,但在所有页面中都说了相同的标题,而且我的文件有很多行,我只需要在文件的一行中包含查询行。

当我说显示全部显示给我时:

arraysize 150
autocommit OFF
autoprint OFF
autorecovery OFF
autotrace OFF
blockterminator "." (hex 2e)
btitle OFF and is the first few characters of the next SELECT statement
cmdsep OFF
colsep "|"
compatibility version NATIVE
concat "." (hex 2e)
copycommit 0
COPYTYPECHECK is ON
define "&" (hex 26)
describe DEPTH 1 LINENUM OFF INDENT ON
echo OFF
editfile "afiedt.buf"
embedded OFF
escape OFF
escchar OFF
feedback OFF
flagger OFF
flush ON
heading OFF
headsep "|" (hex 7c)
instance "local"
linesize 1500
lno 0
loboffset 1
logsource ""
long 80
longchunksize 80
markup HTML OFF HEAD "<style type='text/css'> body {font:10pt Arial,Helvetica,sans-serif;     color:black; background:White;} p {font:10pt Arial,Helvetica,sans-serif; color:black;     background:White;} table,tr,td {font:10pt Arial,Helvetica,sans-serif; color:Black;     background:#f7f7e7; padding:0px 0px 0px 0px; margin:0px 0px 0px 0px;} th {font:bold 10pt     Arial,Helvetica,sans-serif; color:#336699; background:#cccc99; padding:0px 0px 0px 0px;} h1     {font:16pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-color:White;     border-bottom:1px solid #cccc99; margin-top:0pt; margin-bottom:0pt; padding:0px 0px 0px         0px;-
} h2 {font:bold 10pt Arial,Helvetica,Geneva,sans-serif; color:#336699; background-    color:White; margin-top:4pt; margin-bottom:0pt;} a {font:9pt Arial,Helvetica,sans-serif;     color:#663300; background:#ffffff; margin-top:0pt; margin-bottom:0pt; vertical-align:top;}    </style><title>SQL*Plus Report</title>" BODY "" TABLE "border='1' width='90%'         align='center' summary='Script output'" SPOOL OFF ENTMAP ON PREFORMAT OFF
newpage NONE
null ""
numformat ""
numwidth 10
pagesize 0
PAUSE is OFF
pno 0
recsep WRAP
recsepchar " " (hex 20)
release 1002000500
repfooter OFF and is NULL
repheader OFF and is NULL
serveroutput OFF
shiftinout INVISIBLE
showmode OFF
spool ON
sqlblanklines OFF
sqlcase MIXED
sqlcode 0
sqlcontinue "> "
sqlnumber ON
sqlpluscompatibility 10.2.0
sqlprefix "#" (hex 23)
sqlprompt "SQL> "
sqlterminator ";" (hex 3b)
suffix "sql"
tab ON
termout OFF
timing OFF
trimout ON
trimspool ON
ttitle OFF and is the first few characters of the next SELECT statement
underline "-" (hex 2d)
USER is "DMSADMIN"
verify OFF
wrap : lines will be truncated

最佳答案

SQL*Plus 在这方面很笨拙。你可以这样做:

select camp1 || '|' || camp2 || '|' || camp3 || '|' || camp4 from table;

这将执行您想要的操作,但对于大型选择列表可能会很笨拙。

关于sqlplus,以1列导出查询,并且是无序的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20532311/

相关文章:

php - 如何处理 mysql/php 中的 NULL 值?

java - 使用数据库访问的 OOP 编程

java - 设置 SQLNET.ALLOWED_LOGON_VERSION 后 Oracle 监听器状态被阻止

mysql - 当我需要知道另一个表的外键值时,如何将数据插入到一个表中?

sql - 查找某个表的数据源 - ORACLE

sql - 如何在子查询中使用外部列

sql - Oracle SQL : How to use more than 1000 items inside an IN clause

sql - GBQ 窗函数 AND 算术运算

mysql - 创建列和行 mysql

php - 在 MySQL 中使用 distinct 函数