Page 1 of 2

Delete and Insert Oracle OCI-Stage

Posted: Fri Feb 18, 2005 5:25 am
by slk200
Hi there,

i'm extracting data with the SAP BW Extract-Pack. One attribute is YEAR.
I like to write all the extracted data into an oracle table.
Problem is: i like to delete all the existing data of YEAR from the oracle table and then write all the new data into the oracle table.
e.g: extract pack comes with YEAR = 2005
in the oracle table, there are 500 data records with YEAR=2004 and 1000 data records with YEAR=2005 - so the job should delete all the 1000 data records with YEAR = 2005 and then write all the new records.
I tried it with the before-stage: delete from #table# where year:=40 --> problem: not all variables bound

any ideas
thx in advance
matthias

Posted: Fri Feb 18, 2005 5:31 am
by Sainath.Srinivasan
You need to say

delete from #table# where year=40

where 40 is value of field year in the row you expect to delete.

If you are using the OCI stage, you need to use the link variable you pass into it by using something like :1, :2 etc, where :1 stands for first link variable, :2 for second and so on.

Posted: Fri Feb 18, 2005 5:42 am
by slk200
i'm using the oci-stage and :40 is my link variable for YEAR....

Posted: Fri Feb 18, 2005 5:50 am
by Sainath.Srinivasan
Then it must be

delete from #table# where year = :40

Posted: Fri Feb 18, 2005 5:56 am
by slk200
thats what i tried:

**I tried it with the before-stage: delete from #table# where year :=40

Warning:ORA-01008: not all variables bound

Posted: Fri Feb 18, 2005 5:59 am
by Sainath.Srinivasan
Please notice that the colon resides on the right side of the equal-to operator and as a prefix to the number 40.

If this does not work, check whether all you incoming link variables are accounted for.

Posted: Fri Feb 18, 2005 6:00 am
by slk200
and tried it with year = :40 .... ora-01008

Posted: Fri Feb 18, 2005 6:06 am
by slk200
hmmmmm...okay...i have 40 incoming links...in my insert command, all these 40 links are defined, so how to define them in the delete command in the before-tab of the oci-stage, when the only key is YEAR ?

Posted: Fri Feb 18, 2005 6:12 am
by Sainath.Srinivasan
Test with a constant instead of :40. This will give you an idea of whether it is from the 'before stage' or from the insert SQL.

Alternatively re-use the parameter used for YEAR in the source.

Posted: Fri Feb 18, 2005 6:26 am
by slk200
works with a constant, e.g. year = 2005 ......???????

Posted: Fri Feb 18, 2005 6:35 am
by slk200
Problem solved with: delete from #table# where year = year

thx

Posted: Fri Feb 18, 2005 6:38 am
by talk2shaanc
Its an oracle error error code ORA-01008: not all variables bound
Cause: You tried to execute an SQL statement that contained substitution variables where all variables were not bound.
If you just want to delete 2005 records, you can give,
Delete from <tablename> where year=2005

Posted: Fri Feb 18, 2005 6:42 am
by slk200
sorry: problem NOT fixed...delete from #table# where year = year deletes ALL records...

i want to delete all records with year = 2005 but this value (2005) comes from the SAP extract an is not common in advance...

Posted: Fri Feb 18, 2005 7:15 am
by Sainath.Srinivasan
I believe you have defined a parameter, say param_YEAR, to represent the YEAR and used in the query from SAP to return for that YEAR.

You can use the same parameter in your before stage as
delete from #table_name# where year = #param_YEAR#

Posted: Fri Feb 18, 2005 7:32 am
by chulett
As an academic exercise, you can also do this with two links, ordered correctly. :wink:

Have your first output link from the transformer send only the YEAR column to an OCI stage. Constrain it so it only sends one row - the first row. Set the update action to 'delete' based on that single key field and set the transaction size to 1 so the deletes are immediately commited.

Your second link can do the inserts are you are doing them now.