Re: What is the best way to do this?

  • From: Yechiel Adar <adar666@xxxxxxxxxxxx>
  • To: Michael Moore <michaeljmoore@xxxxxxxxx>
  • Date: Tue, 05 Apr 2011 07:33:20 +0300

In this case I think I will normalize it by building a table:
1) Id
2) Attribute name
3) Attribute value

and build a trigger on ABC that will update that table whenever ABC is updated.
Then all you have to do is search on the new table for specific entry

Since we are talking about a customer table is is probably not updated much so the trigger will not hurt you during normal operation.

Yechiel Adar
Israel


On 04/04/2011 20:20, Michael Moore wrote:
Hi Yechiel,

I can't really do that because I am limited to modification only within my PLSQL FUNCTION. I can not change the program that calls my function.


My task is to optimize/rewrite an _existing function_ which looks like:

FUNCTION get_attribute_value (customer_number     IN NUMBER,
                              virtual_column_name IN VARCHAR2)
returns varchar2;

-- where the _return value_ is the value of _one_ of ATTR001 thru ATTR201.

My function does not "know" _all_ of the ATTRibute names, it only know the ONE that it is currently processing.

There might be, for example, 31, 37 or 121 attributes that have a mapping defined, but maybe only 1 of those attributes is required for pricing. For example:

abc_key = 778899
customer # 12345
attribute07 = 3.5  -- student GPA
attribute121 = 95050  -- zip code
attribute129 = Agriculture -- program of interest
attribute134 = 25 -- age

Now lets assume that for this customer we have the business rule that says:
   If the student's age > 23 charge the customer $21
   If the student's age <= 23 charge the customer $29

My function will be passed (778899,'student_age')
My function will SELECT customer# from ABC where abc_key = 778899;
My function will figure out that for customer # 12345, 'student_age' is stored in attribute134.
My function will select attribute134 from ABC where abc_key = 778899;
My function will return '25'

attribute07, 121 and 129 are completely irrelevant to my process as they have no affect on the price.

Thanks for your help,

Regards,
Mike

Other related posts: