blanks lines in between data rows show up when using SPOOL in SQLPlus - oracle

I'm trying to spool a large query in sqlplus but for some reason, I see 2 blank lines every 558 rows to be exact.
I spool as such:
SET TERMOUT OFF
SET ECHO OFF
SET LINES 1000
SET FEEDBACK off
SET HEADING OFF
SET ARRAYSIZE 10000
SET NEWPAGE NONE
SET PAGESIZE 0
SET TRIMSPOOL ON
Spool D:\IPORT15.csv
select query
Spool OFF;
EXIT
I thought SET NEWPAGE was supposed to take care of that??

I was able to resolve this by setting: "SET PAGES 0"

Related

How to spool explain results from Oracle via sqlplus?

I'm having issues with spooling out results from queries, more or less it shows always no real cost, shows rows as one and no cost or anything added, and not the statistics of the actual query.
I'm using this setup:
current_date=$(date +%Y-%m-%d)
sqlplus -S "Username/password#mydatabase.bag" <<EOF >/output/Testoutput_$current_date.log
set verify off;
set colsep ,
SET AUTOTRACE ON
set headsep off
set pagesize 0
set trimspool on
set termout off
col v_spool noprint new_value v_spool
select 'Spoolfile'||
to_char(sysdate,'yyyy_mm_dd_hh24_mi_ss')||'.csv' v_spool from dual;
set termout on
spool /folder/subfolder/&&v_spool
set lines 12345 pages 12345;
EXPLAIN PLAN SET statement_id = 'example_plan1' FOR
select * from dbms.database1_1 where numberline like '%4214%';
SET TIMING OFF
spool off
EXIT
EOF
My wish is to somehow get the explain results spooled to a file, what do I need to modify to achieve this or there is a different approach?
If you try running this in SQL*Plus:
EXPLAIN PLAN SET statement_id = 'example_plan1' FOR
select * from dbms.database1_1 where numberline like '%4214%';
You'll notice that it just outputs:
Explained.
You have to actually select the results of the EXPLAIN PLAN using DBMS_XPLAN - that will get output and spooled to your file.
-- generate the explain plan
EXPLAIN PLAN SET statement_id = 'example_plan1' FOR
select * from dbms.database1_1 where numberline like '%4214%';
-- actually display the results
select plan_table_output
from table(dbms_xplan.display('plan_table',null,'typical'));

Heavy file generated on spooling in unix

I run this code from a unix file.
Please Find Below my code
set colsep ,
set heading off
set pagesize 0
set feedback off
set linesize 32767
set trimspool on
set tab off
spool My_File
select * from my_table; /* it has 45 records*/
spool off;
Once I run this code, I have my output file generated, but the columns are seperated with very big spaces and even the records are seperated with big spaces. As a result I get a very huge file.
Is there any workaround for this ... Thanks in advance..
What i do in these situations is not to use colsep and and do the concatenation myself.
set heading off
set pagesize 0
set feedback off
set linesize 32767
set trimspool on
set tab off
spool My_File
select column1||','||column2||','||column3.... from my_table;
spool off;

How to export half a million records from PL/SQL

I've a table with around 500,000 records. I need all records to be exported in excel. When I query I'm not able to get all as I was said as Out Of memory
Table doesn't have any primary key/Index.
Is there any way to extract?
it would be very easy in to write file output form sqlplus .
mycsv.sql:
SET DEFINE OFF
SET ECHO OFF
SET SERVEROUTPUT OFF
SET TERMOUT OFF
SET VERIFY OFF
SET FEEDBACK OFF
SET PAGESIZE 10000
SET ARRAYSIZE 5000
REM SET HEAD OFF
SET LINE 500
spool /tmp/mycsvfile.csv;
select * from MY_table;
spool off;
exit;
and from Linux prompt you can run like
$> sqlplus username/password #/tmp/mycsv.sql

Prevent Spool to add SQL query in output file

I want my script to stop printing the SQL query in the output file.
I have tried different method, but its just not happening.
sqlplus user/password#(TNS Entry) << EOF
SET head OFF;
SET feed OFF;
SET trimspool ON;
SET linesize 32767;
SET pagesize 32767;
SET echo OFF;
SET termout OFF;
SET verify OFF;
SET NEWPAGE NONE;
SET verify off;
#test.txt
spool file_name.csv
select * from Customer;
spool off
EXIT;
EOF
Could you help please , I want csv file to have just the result of the SQL query and nothing else.
Put your commands in a file. Then run that from SQLPUS.
So for instance make a file query.sql.
SQL>#query.sql
Now SQL won't put the query in the spoolfile.
This way SQLPLUS will listen to your set .. off commands. See the documentation.
*SET ECHO {ON | OFF}
Controls whether or not to echo commands in a script that is executed
with #, ## or START. ON displays the commands on screen. OFF
suppresses the display. ECHO does not affect the display of commands
you enter interactively or redirect to SQLPlus from the operating
system.**

Oracle set multiple system variables

Is it possible to set multiple system variables in a single command?
For e.g. set the below system variables in a single line?
SET COLSEP ' '
SET ECHO OFF
SET FEEDBACK OFF
SET HEADING OFF
SET LINESIZE 10000
SET NEWPAGE NONE
SET TRIMSPOOL ON
Checked http://docs.oracle.com/cd/B19306_01/server.102/b14357/ch12040.htm#i2699283 but don't see an example of doing so.
Is it possible to set multiple system variables in a single command?
Yes you can. Simply specify variable name/value pairs using space as a delimiter between previous variable's new value and the next variable's name. Here is an example:
/* display variables' current values */
SQL> show colsep echo feedback heading linesize
colsep " "
echo OFF
FEEDBACK ON for 6 or more rows
heading ON
linesize 80
/* Assign new values */
SQL> set colsep "|" echo on echo on feedback off heading off linesize 1000;
/* Make sure changes are in effect */
SQL> show colsep echo feedback heading linesize
colsep "|"
echo ON
feedback OFF
heading OFF
linesize 1000
SQL> spool off;
Note: When number of system variables are more than a few, this approach will drastically reduce readability. So it would be better to dedicate each variable/value pair its own SET command.

Resources