Thanks Serge for your tip.
Correction: The import/load into is not into table1(T1) but into
table2(T2). Is there no option from task center or some script to
execute this kind of a logic?
I want to check a table say T1 if it contains records, and if so, then
delete rows in the huge table say T2(I wanted to accomplish this
quicker by load replace with empty file or with "alter table T2
activate not logged initially with empty table"). Then I want to insert
records from T3 to T2.
Serge Rielau wrote:
> hikums@gmail.com wrote:
> > Begin Atomic
> > Declare a integer;
> >
> > Set a=(select count(1) from claims.table1);
> >
> > if a<>0 then
> >
> > import into c:\tmptyfile.txt of del replace into claims.table1;
> > end if;
> > End!
> > Commit!
> >
> > the above returns an error. How do I execute db2 commands inside atomic
> > statement.
> > Error is shown as below:
> >
> > DB21034E The command was processed as an SQL statement because it was
> > not a
> > valid Command Line Processor command. During SQL processing it
> > returned:
> > SQL0104N An unexpected token "into" was found following "table1);
> > db2
> > import". Expected tokens may include: "JOIN". LINE NUMBER=10.
> > SQLSTATE=42601
> >
> BEGIN ATOMIC.. END is an SQL statement, not a command. That's why.
> Now I'm curious on this construct:
> You count all rows just to test whether the table is empty.
> It's a bit like counting stars when the question is whether the night is
> clear. If you speed this up using an EXISTS then maybe you can drive teh
> logic thorugh your app without much problem. You can use a high
> isolation level if you want to make sure noone sneaks in a row.
>
> Cheers
> Serge
>
>
> --
> Serge Rielau
> DB2 SQL Compiler Development
> IBM Toronto Lab