Trango
Trango

Reputation: 21

Apex Data Load : 2 number columns from csv file select 1 based on the condition and load into table

I have a issue in Oracle Apex Data Load which I will try to explain in a simple way:

I want to copy csv data (copy/paste) in Data Load Application and apply the transformation, and rules and load the data into the table BIKE.

I want to create a transformation to check if the column value in the table BIKE is 'blue' then load amount-b other wise amount-a.

Can anyone help me on this?

Thanks

Upvotes: 0

Views: 485

Answers (1)

Jeffrey Kemp
Jeffrey Kemp

Reputation: 60262

Create a staging table, e.g. like this (you will need to adjust the details of the columns to match your data model):

create table bike_staging
(
   apex_session number not null,
   bike_id number not null,
   bike_type varchar2(100) not null,
   amount_a number,
   amount_b number
);

Add a trigger to populate session_id:

create or replace trigger bi_bike_staging
before insert on bike_staging for each row
begin
  :new.apex_session := v('APP_SESSION');
end bi_bike_staging;

Add two processes to the third page of the data load wizard, on either side of the "Prepare Uploaded Data" process, like this:

enter image description here

The code for "delete staging table" will be like this:

delete bike_staging where apex_session = :APP_SESSION;

The code for "load bikes" may be something like this:

merge into bikes t
using (select bike_id,
              bike_type,
              case bike_type
              when 'BLUE' then amount_b
              else amount_a
              end as amount
        from bike_staging
        where apex_session = :APP_SESSION
       ) s
on (t.bike_id = s.bike_id)
when matched then update set
  t.bike_type = s.bike_type,
  t.amount = s.amount
when not matched then insert (bike_id, bike_type, amount)
values (s.bike_id, s.bike_type, s.amount);

delete bike_staging where apex_session = :APP_SESSION;

Alternatively, if you are only inserting new records you don't need the merge, you can use a simple insert statement.

Upvotes: 0

Related Questions