Connecting Tech Pros Worldwide Forums | Help | Site Map

registering a function in discoverer

Familiar Sight
 
Join Date: Jun 2007
Posts: 151
#1: Jul 23 '09
Hi All,

I have a function that return some static value, based on the grade of a person. It takes the person id as the input.

This is my code
Expand|Select|Wrap|Line Numbers
  1. create or replace function fnc_get_employee_emoluments (person_id number) return NUMBER as
  2.     employee_grade varchar2(30);
  3.     first_position number; -- first occurrence of '.' in the grade
  4.     last_position number; -- second occurrence of '.' in the grade 
  5.     string_length number;
  6.     emoluments number := 0;
  7. begin
  8.         SELECT PG.NAME 
  9. FROM HR.PER_ALL_ASSIGNMENTS_F PAAF, hr.PER_GRADES PG
  10. where PAAF.PERSON_ID = 1665 
  11. and PAAF.GRADE_ID = PG.GRADE_ID
  12. and PAAF.effective_end_date =
  13.     (select max(PAAF1.effective_end_date)
  14.      from hr.per_all_assignments_f PAAF1
  15.      where PAAF1.PERSON_ID = PAAF.person_id);
  16. first_position := instr(employee_grade,'.',1,1);
  17. last_position := instr(employee_grade,'.',1,2);
  18. string_length := last_position - (first_position + 1);
  19. employee_grade := substr(employee_grade,first_position + 1,string_length);
  20. IF upper(employee_grade) = 'IZ1' THEN
  21.     emoluments := 668;
  22. ELSIF upper(employee_grade) = 'IZ2' THEN
  23.     emoluments := 881;
  24. ELSIF upper(employee_grade) = 'IZ3' THEN
  25.     emoluments := 1404;
  26. ELSIF upper(employee_grade) = 'IZ4' THEN
  27.     emoluments := 1950;
  28. ELSIF upper(employee_grade) = 'IZ5' THEN
  29.     emoluments := 1434 + 954;
  30.     ELSIF upper(employee_grade) = 'IIZ2' THEN
  31.     emoluments := 1230 + 1230 + 898;
  32. ELSIF upper(employee_grade) = 'IIZ3' THEN
  33.     emoluments := 1076 + 1186 + 1186 + 1109;
  34. ELSIF upper(employee_grade) = 'IIZ4' THEN
  35.     emoluments := 1215 + 1491 + 1491 + 1368;
  36. ELSIF upper(employee_grade) = 'IS3' THEN
  37.     emoluments := 300 + 641;
  38. ELSIF upper(employee_grade) = 'IS4' THEN
  39.     emoluments := 300 + 695;
  40.     ELSE
  41.     emoluments := 0;
  42. END IF;
  43. return emoluments;
  44. end fnc_get_employee_emoluments;
  45.  
Now i compiled this and this runs fine ( returns the correct value), when run in toad.

I registered this in discoverer, and i am using this in calculation item.
It always returns 0. What could be the reason.

I have verified the person id that i am passing in my report. The function return correct value in toad for the same person id but not in my report.

Steps I used to register this function.

1) clicked on register pl/sql function in admin version
2) Clicked on import and searched for this in the available list of functions
3) after adding this, and the parameters, saved the content

In desktop , used the calculation item to retrieve this function.


vamsi

Reply