PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > sql statement inside a here document
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

sql statement inside a here document

Réponse
 
LinkBack Outils de la discussion
Vieux 12/11/2007, 09h44   #1
hyperboogie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut sql statement inside a here document

Hello all

I'm having some problems with an sql statement in a here document.
The following code works fine:
#!/bin/ksh
..
..
result=$(sqlplus -s myuser/mypass@myinstance << EOF
select tname from tab
/
EOF)

echo $result | tr " " "\n"


but when I add a statement with quotes, such as:
#!/bin/ksh
..
..
result=$(sqlplus -s myuser/mypass@myinstance << EOF
select tname from tab where tname like 'MYTABLE'
/
EOF)

echo $result | tr " " "\n"

I get the the content of my home directory and an ORACLE error
message:
..
..
sqlnet.log
testing
users
var
ERROR
at
line
1:
ORA-00904:
"VOUCHER":
invalid
identifier


How can I escape the quotes so that they will be used in the context
of the sql statement?

Thanks

  Réponse avec citation
Vieux 12/11/2007, 14h23   #2
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sql statement inside a here document

On 2007-11-12, hyperboogie <hyperboogie@gmail.com> wrote:
> echo $result | tr " " "\n"
>
> I get the the content of my home directory and an ORACLE error
> message:
> .
> .
> sqlnet.log
> testing
> users
> var
> ERROR
> at
> line
> 1:
> ORA-00904:
> "VOUCHER":
> invalid
> identifier
>
>
> How can I escape the quotes so that they will be used in the context
> of the sql statement?
>

result=$(sqlplus -s myuser/mypass@myinstance << \EOF
echo "$result"
and you might want to check $? or test whether "$result" contains
'ERROR' before changing the spaces to newlines.
  Réponse avec citation
Vieux 13/11/2007, 09h03   #3
hyperboogie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sql statement inside a here document

On Nov 12, 4:23 pm, Bill Marcum <marcumb...@bellsouth.net> wrote:

>
> result=$(sqlplus -s myuser/mypass@myinstance << \EOF
> echo "$result"
> and you might want to check $? or test whether "$result" contains
> 'ERROR' before changing the spaces to newlines.


Sorry, this did not work for me ...
I'm not sure I understood though ...
should I just backslash the first EOF??? cause that's what I did to no
avail .... :-(
am I missing something from your explanation???

  Réponse avec citation
Vieux 13/11/2007, 09h26   #4
Bill Marcum
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sql statement inside a here document

On 2007-11-13, hyperboogie <hyperboogie@gmail.com> wrote:
> On Nov 12, 4:23 pm, Bill Marcum <marcumb...@bellsouth.net> wrote:
>
>>
>> result=$(sqlplus -s myuser/mypass@myinstance << \EOF
>> echo "$result"
>> and you might want to check $? or test whether "$result" contains
>> 'ERROR' before changing the spaces to newlines.

>
> Sorry, this did not work for me ...
> I'm not sure I understood though ...
> should I just backslash the first EOF??? cause that's what I did to no
> avail .... :-(
> am I missing something from your explanation???
>

A backslash on the first EOF would prevent expansion of shell variables
or wildcards in the here document. Apparently that was not your
problem.
  Réponse avec citation
Vieux 13/11/2007, 10h13   #5
hyperboogie
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sql statement inside a here document

On Nov 13, 11:26 am, Bill Marcum <marcumb...@bellsouth.net> wrote:

> A backslash on the first EOF would prevent expansion of shell variables
> or wildcards in the here document. Apparently that was not your
> problem.


No ... the problem (I think) is with the single quotes in the sql
statement:
select tname from tab where tname like 'MYTABLE'

Thanks anyway ... The information about the backslash is useful non-
the-less :-)


  Réponse avec citation
Vieux 13/11/2007, 10h15   #6
Janis
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: sql statement inside a here document

On 13 Nov., 10:26, Bill Marcum <marcumb...@bellsouth.net> wrote:
> On 2007-11-13, hyperboogie <hyperboo...@gmail.com> wrote:> On Nov 12, 4:23 pm, Bill Marcum <marcumb...@bellsouth.net> wrote:
>
> >> result=$(sqlplus -s myuser/mypass@myinstance << \EOF
> >> echo "$result"
> >> and you might want to check $? or test whether "$result" contains
> >> 'ERROR' before changing the spaces to newlines.

>
> > Sorry, this did not work for me ...
> > I'm not sure I understood though ...
> > should I just backslash the first EOF??? cause that's what I did to no
> > avail .... :-(
> > am I missing something from your explanation???

>
> A backslash on the first EOF would prevent expansion of shell variables
> or wildcards in the here document. Apparently that was not your
> problem.


Either way, wildcards are not expanded in here documents.

Janis

  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 06h05.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,18366 seconds with 14 queries