Help supressing spool output from screen when calling sqlplus from script


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Help supressing spool output from screen when calling sqlplus from script
# 1  
Old 08-20-2010
Help supressing spool output from screen when calling sqlplus from script

I'm calling an embedded sql from my shell script file. This sql does simple task of spooling out the contents of the table (see below my sample code) into a spool file that I specify. So far so good, but the problem is that the output is also displayed on screen which I do NOT want.

How can I suppress the output from being displayed on screen while ensuring it still goes to the spool file.

Code:
...
...
sqlplus -s ${ORA_CONN_STR} <<EOF

SET TERMOUT OFF
SET HEADING OFF
SET PAGESIZE 50000
SET LINESIZE 500
SET TRIMSPOOL OFF
SET WRAP OFF
SET FEEDBACK OFF
SET ECHO OFF

SPOOL ${CSV_DIR_FILE}

SELECT 'My header text here'
   FROM dual;
   
SELECT TRIM (field1) || ',' ||
       TRIM (field1) || ',' ||
       TRIM (field2) || ',' ||
       TRIM (field3) || ',' ||
       TRIM (field4)
       ....
   FROM <tablename>;
   
EOF
...
...

# 2  
Old 08-20-2010
U can use :

Code:
sqlplus -s ${ORA_CONN_STR} <<EOF >/dev/null

This User Gave Thanks to Klashxx For This Post:
# 3  
Old 08-20-2010
Bulls eye .. Thanks a lot!
# 4  
Old 08-20-2010
Alternatively, you could redirect to your log file instead of /dev/null.
And not use the SPOOL command explicitly.
Like so -

Code:
$
$
$ cat tst.sh
#!/usr/bin/bash
ORA_CONN_STR="test/test"
CSV_DIR_FILE="tst.log"
sqlplus -s ${ORA_CONN_STR} <<EOF >${CSV_DIR_FILE}
SET TERMOUT OFF
SET HEADING OFF
SET PAGESIZE 50000
SET LINESIZE 500
SET TRIMSPOOL OFF
SET WRAP OFF
SET FEEDBACK OFF
SET ECHO OFF
SELECT 'My header text here'
  FROM dual;
SELECT c1 || ',' ||
       c1 || ',' ||
       c2 || ',' ||
       c3
   FROM t;
EXIT
EOF
$
$ ./tst.sh
$
$ cat tst.log
 
My header text here
 
1,1,10,a
2,2,20,b
3,3,30,c
4,4,40,d
5,5,50,e
$
$

tyler_durden
This User Gave Thanks to durden_tyler For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

SQLPLUS calling Via Script

Hello All, Could you please help me if i am doing anything wrong in below script, especially the sqlplus part performance wise or anything else i could improvise in the script. Thank you. #!/bin/ksh ## Batch Obj Id MP_BCH_OBJ_ID=$1 PASS=$2 partition=$3 ## script dir... (6 Replies)
Discussion started by: Ariean
6 Replies

2. Shell Programming and Scripting

Oracle/SQLPlus help - ksh Script calling .sql file not 'pausing' at ACCEPT, can't figure out why

Hi, I am trying to write a script that calls an Oracle SQL file who in turns call another SQL file. This same SQL file has to be run against the same database but using different username and password at each loop. The first SQL file is basically a connection test and it is supposed to sort... (2 Replies)
Discussion started by: newbie_01
2 Replies

3. Shell Programming and Scripting

Line break in sqlplus output through ksh script

Hi, I am new to shell script programming. I have written a ksh script to run the sql File placed in server directory and spool the output in destination directory. Below Command: $ORACLE_HOME/bin/sqlplus -s $ora_uid @$sqlfile_loc$testquery.sql > $opfiledirectory It is generating the output... (6 Replies)
Discussion started by: Sumit Arora
6 Replies

4. Shell Programming and Scripting

Control not returning from Sqlplus to calling UNIX shell script.

Hello All, I have exactly same issue @vikas_trl had in following link: https://www.unix.com/shell-programming-and-scripting/259854-control-not-returning-sqlplus-calling-unix-shell-script.html I wonder if he or somebody else could find the issue's cause or the solution. Any help would... (4 Replies)
Discussion started by: RicardoQ
4 Replies

5. Shell Programming and Scripting

Control not returning from Sqlplus to calling UNIX shell script.

Hello All, I have a UNIX script which will prepare anonymous oracle pl/sql block in a temporary file in run time and passes this file to sqlplus as given below. cat > $v_Input_File 2>>$v_Log << EOF BEGIN EXECUTE IMMEDIATE 'ALTER SESSION FORCE PARALLEL DML PARALLEL 16'; EXECUTE... (1 Reply)
Discussion started by: vikas_trl
1 Replies

6. UNIX for Dummies Questions & Answers

calling a unix shell script from sqlplus

I want to execute a shell script from sqlplus prompt and get its output back to sqlplus. Is this possible? if yes just give me an example for doing that. (2 Replies)
Discussion started by: boopathyvasagam
2 Replies

7. Shell Programming and Scripting

Need help with a sh script to spool directory and modify the output (Oracle cnt file)

Hi, I'm creating a shell script to dynamically create a recreate controlfile for an Oracle database. I need to read a cold backup file system, and make some changes to these files. Let's say for argument sake the directory name is /ebsprod_c/oradata and it looks like this:... (6 Replies)
Discussion started by: exm
6 Replies

8. Shell Programming and Scripting

Supressing and replacing the output of a field in Awk

Wondering if anybody can help with changing the output of a field. I'm needing to change the output of a field in this file: User Process ID Time Active Licences Type ChangeAdmin (Phys-agsdev/19353 212), start Wed 1/21 6:30 (linger: 1800) u414013 (Phys-agsdev/19353 1491), start Wed 1/21 12:54... (5 Replies)
Discussion started by: Glyn_Mo
5 Replies

9. UNIX for Dummies Questions & Answers

SQLPlus spool file

HI Have some problem with spooling out some relatively large number of records (~2-3 mil) Small table - OK though. Getting error: SP2 0308: cannot close spool file. Any thoughts? sqlplus -s user/pwd << EOF set term off set head off set trims on set pages 0 set... (1 Reply)
Discussion started by: Leo_NN
1 Replies

10. Shell Programming and Scripting

code to FTP the spool file from Sqlplus to the unix server.

I have a sqlplus report and inside that report I have the following piece of code to mail the report output to the email id. My requirement is, instead of emailing the output I want to FTP that script to a different unix server (say ip as 10.10.1.1). How to modify this code to FTP the spool file... (0 Replies)
Discussion started by: vprevin
0 Replies
Login or Register to Ask a Question