0

I have a table that we use for import some data. This table have field like this:

  • field_1
  • field_2
  • field_3

After the import is done, I call a postprocess procedure where I have to do some logic in this field (and the logic could be different for each one of this) and store in online table.

This is a possible pseudo-code:

DECLARE
    rOnlineTable online_table%ROWTYPE;
FOR cur in (SELECT *
              FROM import_table
             WHERE state IS NULL)
LOOP

  rOnlineTable.online_field_1 := handleField(/* here i would like to call a function that have the logic to handle cur.field_1*/);
  rOnlineTable.online_field_2 := handleField(/* here i would like to call a function that have the logic to handle cur.field_2*/);
  rOnlineTable.online_field_3 := handleField(/* here i would like to call a function that have the logic to handle cur.field_3*/);

  INSERT INTO online_table VALUES rOnlineTable;

END LOOP;

In this way (I think) I could change only the implementation of the handler methods if in future something will change. Or I can swap some of that handler-function for other fields (for example: tomorrow field_1 need the same logic as field_3).

There are some workaround to do this, or maybe another better solution ?

2
  • 1
    I'm not sure that I see a question here. Or at least I don't understand the question you're asking. Why can't you create a function that takes a parameter of type cur.field_1 and returns a value of type rOnlineTable.online_field_1? Commented Mar 13, 2015 at 14:15
  • Are these handler functions going to be used elsewhere, or is the code involved long and complex? If so, then by all means use a function. If not, however, all you're doing is reducing clarity and adding complexity. ??? Commented Mar 15, 2015 at 17:18

1 Answer 1

1

What about simple insert statement?

insert into online_table select func1(field1), func2(field2), func3(field3)   from import_table

where func1..3 would look like

  create or replace function func1(a in import_table.field1%type) return   online_table.field1%type as
begin
  null; //some logic
end;
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.