dbTalk Databases Forums  

Avoiding spooling to empty files

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Avoiding spooling to empty files in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
CenturionX
 
Posts: n/a

Default Avoiding spooling to empty files - 01-30-2009 , 02:53 PM






Hello,

I'm working with Oracle 10.2.0.4.0

I have an unix script that via command line executes a query

$ORACLE_HOME/bin/sqlplus -silent <<EOF
connect user/pass@databse
set pagesize 0
set heading off
set echo off
set term off
set feedback off
set linesize 126
spool /tmp/file_to_send
SELECT * FROM table;
EOF

The issue is that if there is not data it generates a file with a
control caracter (Don't know which one).

I want to know how to avoid file generation via SQLPLUS commands or at
least don't send any invisible caracter to the file.

Thanks.

Reply With Quote
  #2  
Old   
ddf
 
Posts: n/a

Default Re: Avoiding spooling to empty files - 01-30-2009 , 03:14 PM






On Jan 30, 2:53*pm, CenturionX <darwinbaldr... (AT) gmail (DOT) com> wrote:
Quote:
Hello,

I'm working with Oracle 10.2.0.4.0

I have an unix script that via command line executes a query

$ORACLE_HOME/bin/sqlplus -silent <<EOF
* * * * connect user/pass@databse
* * * * set pagesize 0
* * * * set heading off
* * * * set echo off
* * * * set term off
* * * * set feedback off
* * * * set linesize 126
* * * * spool /tmp/file_to_send
* * * * SELECT * FROM table;
EOF

The issue is that if there is not data it generates a file with a
control caracter (Don't know which one).

I want to know how to avoid file generation via SQLPLUS commands or at
least don't send any invisible caracter to the file.

Thanks.
Your syntax is wrong for silent mode as I consistently see errors from
your use of 'connect':

$ $ORACLE_HOME/bin/sqlplus -silent
connect bing/########
SP2-0306: Invalid option.
Usage: CONN[ECT] [logon] [AS {SYSDBA|SYSOPER}]
where <logon> ::= <username>[/<password>][@<connect_identifier>] | /

'Connect' works with sqlplus /nolog:

$ $ORACLE_HOME/bin/sqlplus /nolog

SQL*Plus: Release 10.2.0.3.0 - Production on Fri Jan 30 15:10:00 2009

Copyright (c) 1982, 2006, Oracle. All Rights Reserved.

SQL> connect bing/########
Connected.
SQL>

For silent mode all one needs is the user/pass@database string:

$ $ORACLE_HOME/bin/sqlplus -silent
system/*&*&*&*&*&*&*&*&@smork


The blank line following the login credentials indicates a successful
login. Modifying your script:

$ORACLE_HOME/bin/sqlplus -silent <<EOF
user/pass@databse
set pagesize 0
set heading off
set echo off
set term off
set feedback off
set linesize 126
spool /tmp/file_to_send
SELECT * FROM table;
EOF

connects successfully and returns a 1-line, 1 character file with no
control characters present.


David Fitzjarrell


Reply With Quote
  #3  
Old   
CenturionX
 
Posts: n/a

Default Re: Avoiding spooling to empty files - 01-30-2009 , 04:50 PM



Thanks David

I actually did the corrections. But i need the file zero lenght when
there is no data to spool. Do you know a way to do that. Be generate a
zero-lenght file or not generated it at all.

Thanks.

Reply With Quote
  #4  
Old   
CenturionX
 
Posts: n/a

Default Re: Avoiding spooling to empty files - 01-30-2009 , 05:16 PM



Is there a database configuration for this or maybe an Unix parameter
too???

Thanks.

Reply With Quote
  #5  
Old   
joel garry
 
Posts: n/a

Default Re: Avoiding spooling to empty files - 01-30-2009 , 05:25 PM



On Jan 30, 2:50*pm, CenturionX <darwinbaldr... (AT) gmail (DOT) com> wrote:
Quote:
Thanks David

I actually did the corrections. *But i need the file zero lenght when
there is no data to spool. Do you know a way to do that. Be generate a
zero-lenght file or not generated it at all.

Thanks.
Well, are you sure you want this? Here's one hint:

$ echo " " > xx
$ if [ `find . -size 1c -name xx` ]
Quote:
then echo "yes"
else echo "no"
fi
no
$ echo "" > xx
$ if [ `find . -size 1c -name xx` ]
Quote:
then echo "yes"
else echo "no"
fi
yes
$ echo "\c">xyz
$ ll xyz
-rw-rw-rw- 1 jeg users 0 Jan 30 15:25 xyz

Do what you want instead of echo.

jg
--
@home.com is bogus.
http://www3.signonsandiego.com/stori...ion/?uniontrib


Reply With Quote
  #6  
Old   
CenturionX
 
Posts: n/a

Default Re: Avoiding spooling to empty files - 01-30-2009 , 06:27 PM



Thanks Joel,

Actually it is very usefull.

I'll try to implement it.

The only inconvinient is that i'm migrating a lot of scripts that
worked fine (generated zero-lenght files when no data found).

So i'll still need the trick for Oracle.

Thanks.

Reply With Quote
  #7  
Old   
Malcolm Dew-Jones
 
Posts: n/a

Default Re: Avoiding spooling to empty files - 01-30-2009 , 08:16 PM



CenturionX (darwinbaldrich (AT) gmail (DOT) com) wrote:
: Hello,

: I'm working with Oracle 10.2.0.4.0

: I have an unix script that via command line executes a query

: $ORACLE_HOME/bin/sqlplus -silent <<EOF
: connect user/pass@databse
: set pagesize 0
: set heading off
: set echo off
: set term off
: set feedback off
: set linesize 126
: spool /tmp/file_to_send
: SELECT * FROM table;
: EOF

: The issue is that if there is not data it generates a file with a
: control caracter (Don't know which one).
^^^^^^^^^^^^^^^^^^^^

on usix, use od (octal dump) to examine the file.

I like
od -a YOUR-FILE

(-a = show bytes using character notation, which is often easier to read)

$0.10

Reply With Quote
  #8  
Old   
ddf
 
Posts: n/a

Default Re: Avoiding spooling to empty files - 01-31-2009 , 10:03 AM



On Jan 30, 6:27*pm, CenturionX <darwinbaldr... (AT) gmail (DOT) com> wrote:
Quote:
Thanks Joel,

Actually it is very usefull.

I'll try to implement it.

The only inconvinient is that i'm migrating a lot of scripts that
worked fine (generated zero-lenght files when no data found).

So i'll still need the trick for Oracle.

Thanks.
set trimspool on

That causes SQL*Plus to 'trim' the trailing spaces, and it may just
fix your 'problem'.


David Fitzjarrell


Reply With Quote
  #9  
Old   
CenturionX
 
Posts: n/a

Default Re: Avoiding spooling to empty files - 02-05-2009 , 12:36 PM



Thanks everybody,

I tried the trimspool on but it didn't work.

I noticed i forgot the spool off, so i included it in the script. I
ran it again an it worked. I have my zero-lenght file.

Thanks.


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.