loop problem

Hi guys my while do loop is not working properly;
As soon as the load_date and run_date is same it should stop can somebody tell me where I am having the problem?
In an oracle table I have
LOAD_DT=5/1/2009 DATE datatype
RUN_DT=5/5/2009 DATE datatype
Now in a script with a spool file I get the dates in char type
v_LOAD_DT==`head -n1 $spool | awk '{print $1}'`(20090501)
v_RUN_DT==`head -n1 $spool | awk '{print $1}'`(20090505)
while [$v_LAST_LOAD_DT -lt $v_RUN_DT]
do
#{Here I am incrementing the date]
sqlplus /nolog @increment.SQL $calc_spool
if [$? -ne 0]; then exit 1; fi
v_next_dt=`head -n1 $calc_spool | awk '{print $1}'`
echo "$v_NEXT_DT"
[$v_NEXT_DT -eq $v_RUN_DT]
#[Here I am updating the table with the next day ]
sqlplus /nolog @Update_dt.SQL $v_update
if [$? -ne 0]; then exit 1; fi
done
The problem with the syntax is the loop is not stopping. when the load_dt=run_dt the loop should stop.
But when I force it to stop I see the load_dt to be a much later date.I dont think the while do syntax is right.
And it seems it is not recognising [$v_NEXT_DT -eq $v_RUN_DT] syntax.
Can you tell me what is the problem?
Thanks in advance

I think you should make sure that your variables are proper integers.
You can use "typeset -i name=value" or "integer name=value".
Unless you use integers, your condition would not work.

There must be a space after the opening bracket and a space before the closing bracket in your test statements, for example:

while [ $v_LAST_LOAD_DT -lt $v_RUN_DT ]

instead of:

while [$v_LAST_LOAD_DT -lt $v_RUN_DT]

Regards

yes as franklin mentioned you need a space after "[" in every loop such as if while etc

I got those spaces but still i am facing the same problem. IS my while do loop logic ok.

why are you referencing the SAME field ($1) for both variables?

Also.......

v_LOAD_DT=$(awk 'FNR==1 {print $1;exit}' "${spool}")

Thanks vgersh,

But that is not what I am looking at and I apologise that I confused you.

I should explain because I am really stuck.

In an oracle table I have
LOAD_DT=5/1/2009 DATE datatype
RUN_DT=5/5/2009 DATE datatype

with the help of spool file I am picking these variables up like 02-MAY-2009 and 05-MAY-2009

Now my question is with a do while loop I need to get the dates 03-MAY-2009, 04-MAY-2009 and 05-MAY-2009.

I am confused at where to initialize and totally confused with the loop.

I did this

while [ $LOAD_DT -lt $RUN_DT ]
do

#Here I will write a sqlplus code to increment the date
#I will get my other work done here

stop condition

done

#Here I will update my table with the next day sqlplus code

Just please suggest me the do while loop syntax for this case and the stop condition.
I am sure I am messing up at the initialising or stop condition.

Thanks to all of you,

for comparing date get the date in YYYYMMDD format from sqlplus using date functions then its easy to compare them in while loop. and later you can convert it to your desired form using date function..
NOTE:-there is no need to spool if you are selecting a single date i mean single line
you can directly take it in variable

I think the problem is using shell instead of pl/sql for the while loop, e.g. at the sqlplus prompt...

SQL> set serveroutput on
SQL> DECLARE
  2      d1 DATE := to_date('01-MAY-09');
  3      d2 DATE := to_date('05-MAY-09');
  4  BEGIN
  5      WHILE d1 < d2
  6      LOOP
  7          d1 := d1 + 1;
  8          dbms_output.put_line('Use ' || to_char(d1, 'DD-MON-YY'));
  9      END LOOP;
 10  END;
 11  /
Use 02-MAY-09
Use 03-MAY-09
Use 04-MAY-09
Use 05-MAY-09

PL/SQL procedure successfully completed.

Instead of using

while [ $LOAD_DT -lt $RUN_DT ]

try

while [[ $LOAD_DT < $RUN_DT ]]

I feel that the variables LOAD_DT & RUN_DT are not integer/numeric values in it.
Whenever we go for String one then we need to use like I mentioned. Try this. Anybody has anything to Say.

Thanks,
Shahnaz.

"[[" works in bash not in ksh

"[[" works in bash and in ksh

????:confused:

 
 home> while [[ : ]] ; do
ksh: 0403-057 Syntax error: `]' is not expected.
home> echo $SHELL
/usr/bin/ksh
home>

You can get away with that in bash but ksh expects a comparison expression, like [[ x < y ]]

Gurus , I got it resolved. Thanks to all of you for ur help.

so that means "[[" you can't generalize that in ksh
thats why i usually tend to give general info