Re: Unix to Oracle / Back
From: joel garry <joel-garry_at_home.com>
Date: Thu, 16 Jul 2009 15:35:37 -0700 (PDT)
Message-ID: <cb245079-819f-4d55-8022-58a8a0bc1f59_at_t11g2000prh.googlegroups.com>
On Jul 16, 2:03 pm, The Magnet <a..._at_unsu.com> wrote:
> I'm trying to accomplish this:
>
> estimates=`sqlplus -s $user/${password} << " EOF"
> set heading off feedback off verify off timing off
> SELECT count(*)
> FROM daily_estimates
> WHERE TO_CHAR(date_appended,'YYYYMMDD') = '$yyyymmdd';
> exit
> EOF`
>
> I get nothing. If I hard code an actual date in there, it works
> fine. Why is Oracle not resolving the variable? I've seen this on
> many pages and it works fine there.......
>
> Oracle 10g R2. Using ksh......
>
> Many thanks!
estimates=`sqlplus -s $user/${password} <<EOF set heading off feedback off verify off timing off SELECT count(*),'blorf','$yyymmdd'
FROM dual;
exit
EOF
`
echo $estimates
Date: Thu, 16 Jul 2009 15:35:37 -0700 (PDT)
Message-ID: <cb245079-819f-4d55-8022-58a8a0bc1f59_at_t11g2000prh.googlegroups.com>
On Jul 16, 2:03 pm, The Magnet <a..._at_unsu.com> wrote:
> I'm trying to accomplish this:
>
> estimates=`sqlplus -s $user/${password} << " EOF"
> set heading off feedback off verify off timing off
> SELECT count(*)
> FROM daily_estimates
> WHERE TO_CHAR(date_appended,'YYYYMMDD') = '$yyyymmdd';
> exit
> EOF`
>
> I get nothing. If I hard code an actual date in there, it works
> fine. Why is Oracle not resolving the variable? I've seen this on
> many pages and it works fine there.......
>
> Oracle 10g R2. Using ksh......
>
> Many thanks!
Oddly, this also works:
yyymmdd=`date`
user=xxx
password=yyy
echo $user echo $password echo $yyymmdd
estimates=`sqlplus -s $user/${password} <<EOF set heading off feedback off verify off timing off SELECT count(*),'blorf','$yyymmdd'
FROM dual;
exit
EOF
`
echo $estimates
The issue is that (per Unix Power Tools) white space and newlines both become argument separators when in backquotes. That's why you can put a command that outputs things on separate lines in backquotes and they are treated as though they are parameters on the same line. That's not the trick I thought I was about to remember. That's not how I always thought putting quotes around a hereis delimiter worked - when I first started this second post, I had thought a backslash was necessary on the line before the EOF to force the newline not to be like whitespace. Learn something new every day.
jg
-- _at_home.com is bogus. http://blog.mozilla.com/security/2009/07/14/critical-javascript-vulnerability-in-firefox-35/Received on Thu Jul 16 2009 - 17:35:37 CDT