Set heading off is not working in SQLcl when set sqlformat csv - oracle

I am generating a csv output using SQLcl.
set sqlformat csv
set heading off
select * from hr.employees where rownum < 10;
"EMPLOYEE_ID","FIRST_NAME","LAST_NAME","EMAIL","PHONE_NUMBER","HIRE_DATE","JOB_ID","SALARY","COMMISSION_PCT","MANAGER_ID","DEPARTMENT_ID"
100,"Steven","King","SKING","515.123.4567",17-JUN-03,"AD_PRES",24000,,,90
101,"Neena","Kochhar","NKOCHHAR","515.123.4568",21-SEP-05,"AD_VP",17000,,100,90
102,"Lex","De Haan","LDEHAAN","515.123.4569",13-JAN-01,"AD_VP",17000,,100,90
103,"Alexander","Hunold","AHUNOLD","590.423.4567",03-JAN-06,"IT_PROG",9000,,102,60
104,"Bruce","Ernst","BERNST","590.423.4568",21-MAY-07,"IT_PROG",6000,,103,60
But I am getting the heading which I don't want. I imagine set heading off should turn off the heading (as it does in SQLPlus) why it's not working in SQLcl. If I clear the sql formatting (set sqlformat) then heading off works. Is it a bug in SQLcl?

SET PAGESIZE 0
lets you run without pagination.
set heading off
should work, but was broken. The next release will have it fixed...like this
Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production
BARRY#orcl☘ >set sqlformat csv
BARRY#orcl☘ >set heading off
BARRY#orcl☘ >select * from demo;
1,"Barry"
2,"Lisa"
3,"Rebecca"
4,"Katie-Ellen"
BARRY#orcl☘ >

Using the current version of sqlcl (as of 6/30/2017), with both 11g and 12c databases, works fine:
alter session set NLS_DATE_FORMAT='DD-MON-YYYY';
set feedback off
set sqlformat csv
spool <spool loc>
SELECT <column list> FROM <table list> WHERE <where clause
ORDER BY <order by clause>;
spool off;

You don't want to see the headings in the results?
In SQLPLUS you can use
set pagesize 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'));

Using dollar sign in sqlplus spool file

How to use file name with dollar sign (ie, '$') in unix like below
SQL> spool DIR$work.sql
SP2-0332: Cannot create spool file.
and i tried like below
SQL> spool DIR\$work.sql
SP2-0332: Cannot create spool file.
SQL> spool 'DIR\$work.sql'
SP2-0332: Cannot create spool file.
SQL> spool 'DIR$work.sql'
SP2-0332: Cannot create spool file.
I couldn't succeed in any way to create such file in oracle.
I have oracle 11g version.
In windows sqlplus it works fine.
You can use the set escchar setting to stop Oracle interpreting the dollar sign:
SQL> show escchar
escchar OFF
SQL> spool /tmp/$work.sql
SP2-0332: Cannot create spool file.
SQL> set escchar $
SQL> spool /tmp/$work.sql
SQL>
You are now spooling to that file name.
SQL> select * from dual;
D
-
X
1 row selected.
SQL> spool off
SQL> exit
Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
...
$ cat /tmp/\$work.sql
SQL> select * from dual;
D
-
X
1 row selected.
SQL> spool off
Also see My Oracle Support document 761384.1 for more information.

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

Remove Column Header into the Output Text file

I want to create a flat file (text file) of my query from Oracle SQL Developer.
I have successfully created the text file using SPOOL, thru a script text file, but i want to remove the header of each column into my output.
I am getting this output:
Header000001 Header000002
------------ ------------
Adetail1 Bdetail1
Adetail2 Bdetail2
Adetail3 Bdetail3
But, I want to get this output:
Adetail1Bdetail1
Adetail2Bdetail2
Adetail3Bdetail3
I already tried the command "set heading off", but a message says:
"SQLPLUS COMMAND Skipped: set heading off".
These are the inputs I've issued:
spool on;
spool C:\SQLFiles\PSB_ATMLKP.txt;
set newpage 0;
set echo off;
set feedback off;
set heading off;
select terminal_number, terminal_name from terminal_table;
spool off;
SQLPLUS COMMAND Skipped: set heading off
That message is most likely because you are not executing it through SQL*Plus, but some GUI based tool. You are using SQLPlus command in SQL Developer. Not all SQL*Plus commands are guaranteed to work with SQL Developer.
I would suggest you execute the script in SQLPlus and you would see no issues.
You need:
SET HEADING OFF
This will not include the column headers in the output.
Alternatively, you could also do this:
SET PAGESIZE 0
Using SQL Developer Version 3.2.20.10:
spool ON
spool D:\test.txt
SET heading OFF
SELECT ename FROM emp;
spool off
Spool file got created with no issues:
> set heading OFF
> SELECT ename FROM emp
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
JAMES
FORD
MILLER
14 rows selected
Add:
set underline off
to the beginning of the SQL script.
In my SQL scripts I have:
SET TERMOUT OFF
set colsep |
set pagesize 0
set trimspool on
set pagesize 0 embedded on
SET heading on
SET UNDERLINE OFF
spool file_path
-- your SQL here
spool off
See this book for reference.

Oracle 11g Report Problem

Hey friends i am using Oracle 11G. I wanted to generate reports for printing , SO i write this script
rem Employee Salary Report
set headsep !
ttitle 'Salary Report'
btitle 'From Employees'
column employee_id format 999.99
column first_name format a20
column last_name format a20
column Salary format 999.99
break on employee_id skip 1 on report
set linesize 80
set pagesize 5
set newpage 0
set feedback off
set pause 'More...'
set pause on
spool activity.lst
select employee_id,first_name,last_name,salary from Employees order by employee_id ;
spool off
When running this script oracle gives
line 3: SQLPLUS Command Skipped: set headsep !
line 15: SQLPLUS Command Skipped: set linesize 80
line 16: SQLPLUS Command Skipped: set pagesize 5
line 17: SQLPLUS Command Skipped: set newpage 0
and then it executes query and gives output. But my report doesn't include any title in it.Means reports is not generated properly. It just simply executes the select query and gives an output which is not a report.
Did you have a question?
What you show us looks very much like the output we would expect if your script was run from the SQL Worksheet in Oracle SQL Developer.
Those commands that are being skipped are specific to SQL*Plus, and are not supported in SQL Developer (at least, in the version I'm running).
To get a formatted report produced by SQL*Plus, I would run the sqlplus executable from the OS e.g.
> $ORACLE_HOME/bin/sqlplus /
SQL> #/home/spencer7593/myreport.sql
SQL> exit
>
I'm not sure that answers a question, since I don't know what your question was.

Resources