sqlplus: could it be dirrected do not printout anything, beside results?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting sqlplus: could it be dirrected do not printout anything, beside results?
# 1  
Old 07-09-2009
sqlplus: could it be dirrected do not printout anything, beside results?

I try to prepare a sufficient function to execute a sql-statement, getting back ONLY retrieved results!

What I can't figured out how to make the sqlplus not printing the 'Connected to ...', 'Disconnected from...' and the executed statements after 'SQL> '.

I am under impression that having the sqlplus suppress that information by itself, than filtering it outside of the sqlplus by 'grep' or 'sed', will be quicker

I have tried the
'sqlplus $cred @sql_script' and
'sqlplus $cred <<EofSQL'
Last one works better, but I am spooling and filtering the '^SQL> ' lines.

I would like to do not involve the 'sed ' and spool file.
Would be the best to make sqlplus avoid printing beginning and end information and accept SQL-statements silently!

Does anyone know how and if it possible at all to do?
That what I have by now (just for reference)
Code:
run_sql ()
{
    #change the SQL-way-comments (--...\n )  to C-style: (/* ... */\n)
  sql_cmd=$(echo "$*" |sed ' /--/s/$/\*\//;/--/s/--/\/\*/g;');
  sqlplus $AIM_PSWD >/dev/null <<STOP_SQLPLUS
      -- do not display summary of sql-command execution
    set FEEDBACK OFF
      -- do not display collumn names in sql execution results
    set HEADING OFF
      -- followed 2 should improve performance
    set APPINFO OFF
    set DEFINE OFF
      -- this one sets the secondary prompt to main one (that is used when sql-statement use more than 1 line)
    set SQLNUMBER OFF
    set linesize 1000
    spool sqlplus.rsl
    $sql_cmd
STOP_SQLPLUS

    rc=$?;
    sed "/SQL/d; /^$/d; /^[ ]*$/d" sqlplus.rsl
return $rc
}

# 2  
Old 07-10-2009
set auto off
set echo off
# 3  
Old 07-10-2009
Appreciate replay, vbe, but doesn't work. (Actualy, I have tried that already. Maybe there is something that prevent that sets to work?)
Code:
--44672:/export/home/dca0701/develop/src/ReLINK> run_tst()
> {
> sqlplus $AIM_PSWD <<!
> set FEEDBACK OFF
> set HEADING OFF
> set AUTO OFF
> set ECHO OFF
> $*
> !
> }
--44674:/export/home/dca0701/develop/src/ReLINK>
--44674:/export/home/dca0701/develop/src/ReLINK> run_tst "select sysdate
> from dual
> ;
> "

SQL*Plus: Release 9.2.0.6.0 - Production on Fri Jul 10 10:51:31 2009

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.


Connected to:
Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production
With the Partitioning option
JServer Release 9.2.0.6.0 - Production

SQL> SQL> SQL> SQL> SQL>   2    3
10-JUL-09
SQL> SQL> Disconnected from Oracle9i Enterprise Edition Release 9.2.0.6.0 - Production
With the Partitioning option
JServer Release 9.2.0.6.0 - Production

I need just like this:
Code:
--44675:/export/home/dca0701/develop/src/ReLINK> run_sql "select sysdate
> from dual
> ;
> "
10-JUL-09
--44676:/export/home/dca0701/develop/src/ReLINK>

Is there any way to make those sets to work, or any other way to eliminate those stuff??
# 4  
Old 07-10-2009
Can you please explain, what exact output you need and what you get?..
# 5  
Old 07-12-2009
Quote:
Originally Posted by alex_5161

I need just like this:
Code:
--44675:/export/home/dca0701/develop/src/ReLINK> run_sql "select sysdate
> from dual
> ;
> "
10-JUL-09
--44676:/export/home/dca0701/develop/src/ReLINK>

Is there any way to make those sets to work, or any other way to eliminate those stuff??
Maybe something like this ?

Code:
$ 
$ cat run_sql
#!/bin/bash
sqlplus -s /nolog <<EOF >sqlplus.rsl
connect test/test
set heading off
$1
EOF

$ 
$ ./run_sql "select sysdate
> from dual
> ;
> "
$ cat sqlplus.rsl

11-JUL-09

$ 
$

tyler_durden
# 6  
Old 07-13-2009
Yes, durden_tyler, that '-s' is what I was looking for!
Appreciate it!!

One difference from your example is that for me the 'connect ..' command always shows '>connected' output (but I did not redirect to file; I use std-output; but, it shouldn't be a matter, right)
Code:
src> typeset -f run_his
run_sql1 ()
{
    sqlplus -s /nolog  <<EOF
connect $AIM_PSWD
set FEEDBACK OFF
set HEADING OFF
set APPINFO OFF
set DEFINE OFF
set linesize 1000
$*
EOF

}
src>
src> run_sql1 "
;
> select sysdate
> from dual
> ;
> "
Connected.

13-JUL-09
src>

It is not a problem, just surprising. I have changed '/NOLOG' to the connection string (in my exml it is $AIM_PSWD) and 'connected ' disapeared.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk --> selective printout with FNR

Hi everybody! need some awk-support. i want a line-selective printout of a file. wat i normally will do with ... awk ' FNR==8' sample.txt But now i need the data from line 8, 10 and the following data from line13 to 250 wich is not end of the file. I tried allready to combine it but without... (2 Replies)
Discussion started by: IMPe
2 Replies

2. Shell Programming and Scripting

Sqlplus error - sqlplus -s <login/password@dbname> : No such file or directory

i am using bash shell Whenever i declare an array, and then using sqlplus, i am getting sqlplus error and return code 127. IFS="," declare -a Arr=($Variable1); SQLPLUS=sqlplus -s "${DBUSER}"/"${DBPASS}"@"${DBASE} echo "set head off ; " > ${SQLCMD} echo "set PAGESIZE 0 ;" >> ${SQLCMD}... (6 Replies)
Discussion started by: arghadeep adity
6 Replies

3. Debian

hardware printout layout terminology

trying to find online or a book. the words to use to find 'a' or 'the ways and means' to format left margin, right margin etc from man pages to Hardware Printer. while looking to print man pages with a Hardware Printer. I have found lp. and did a man sudoers | lp -p2 to test. The... (1 Reply)
Discussion started by: cowLips
1 Replies

4. Shell Programming and Scripting

Can ctag and cscope support recording search results and displaying the history results ?

Hello , When using vim, can ctag and cscope support recording search results and displaying the history results ? Once I jump to one tag, I can use :tnext to jump to next tag, but how can I display the preview search result? (0 Replies)
Discussion started by: 915086731
0 Replies

5. Shell Programming and Scripting

iterating over results from sqlplus

hi all, i am writing a ksh script, i am logging into an oracle db via sqlplus and running a select statement but i dont know how i can store the results from the sql so i can iterate over it and do more operations over it. I dont want to write a stored procedure with a cursor since i need to... (2 Replies)
Discussion started by: cesarNZ
2 Replies

6. UNIX and Linux Applications

linux sqlplus select results writes into file twice

Hello, This is my first post and its because I could not find solution for myself I decided to ask help here. What I want to do; I want to get some data from a table 1 on server 1 and insert those datas into a table 2 on server 2. ( lets say schema names are server1 and server 2 also ).... (10 Replies)
Discussion started by: azuahaha
10 Replies

7. Shell Programming and Scripting

Help with awk printout

I want to represent the columns by whats in a txt file. So the columns.txt file contains "$2$3" and the test.txt file contains "bob tom jones jon" I have #!/bin/bash columnsVar=`cat columns.txt` echo "Columns edited: $columnsVar" awk ' {print $columnsVar }' test.txt But it prints out... (1 Reply)
Discussion started by: Bandit390
1 Replies

8. UNIX for Advanced & Expert Users

Set shell variables from SQLPLUS query results

Hi All, I needed to get the result of two sqlplus queris into shell variables. After days of looking for the ultimate solution to this problem.. i found this... sqlplus -s USER/PASS@DB <<EOF | awk '{if(NR==1) printf("%s ", $1); if(NR==2) printf("%s ", $1);}' | read VAR1 VAR2 set head off... (2 Replies)
Discussion started by: pranavagarwal
2 Replies

9. SCO

How to remove date and page header from a printout

I have some HP4+ and HP5 printers printing from Unixware 7.1.4. The problem is that they print a page header with the date and page number. I can't seem to figure out how to stop this. These headers through the pagination off. (2 Replies)
Discussion started by: sladeburke
2 Replies

10. Red Hat

How to take printout of linux file from windows xp using putty?

Friends, I have installed Putty in my windows xp pc. I am connecting the RHEL AS 3 server using putty from my windows xp. My printer is connected to my windows xp. Now, i want to print text.txt of RHEL AS 3.0 in my windows xp printer through putty. For Example: my pc ip is 117.23.2.55... (3 Replies)
Discussion started by: sathyguy
3 Replies
Login or Register to Ask a Question