[NTLUG:Discuss] OT: sql embedded in shell script (sh) passingparameters

Jack Snodgrass jack+ntlug at mylinuxguy.net
Fri Sep 5 08:08:22 CDT 2003


> I am not all together sure what is happening here, and any questions or
> advise would be most welcomed.
>
> I have  a bit of sql (sqlplus as a matter of fact) embedded in a shell
> script, such as shown below.  The sql works fine by itself, and worked
> fine until we added the "AND" phrase shown.  The issue seems to be that
> the $InvType is character, and should be enclosed in "single quotes"
> (example: AND ih.inv_type = 'REB'), but nothing I do seems to work.  I
> don't want to muddy the water with a lot of my own conjecture, so I'll
> stop right there, and repeat the offer of more details upon request.
>
> Thank you in advance for any help you may be able to offer.
>
> <Code Snippet>
> sqlplus username/password at sid << EOF
> (omitted for brevity)
> AND ih.inv_type = $InvType
> /
> exit
> EOF
> <\Code Snippet>

Which shell? That might make a difference.

When you say $InvType, do you expect it to be
converted to a variable from the script or taken
from the enviornment variables or used as-is.


in bash...
export tmpCH_DOC_ID="sometext"
then run a program that contains:

#!/bin/bash
sqlplus usrid/passwd at sid << EOF
select CH_DOC_ID from scm_build_info where CH_DOC_ID = '$tmpCH_DOC_ID';
/
exit
EOF

runs the sql query:
select CH_DOC_ID from scm_build_info where CH_DOC_ID = 'sometext';
successfully.

jack





More information about the Discuss mailing list