Wednesday, 28 August 2013

Oracle Function to hardCode Column Name as Parameter

Oracle Function to hardCode Column Name as Parameter

i have 2 tables with Same set Column Name (52+ coulmns) . I need to write
a Oracle Functiona to compare whether any records get changed between
these columns. EMP ID is the Primary Key
im trying to use the below Function. but it is giving me incorrect result,
and im calling the funcaiton like this:- get_data_change (emp_id,
'DEPT_NAME'); get_data_change (emp_id, 'PHONE_NUMBER');
Function i have created.`
CREATE OR REPLACE function get_data_change ( in_emp_id varchar2,
in_Column_Value varchar2 )
return char is
v_data_changed char;
begin
select eid in_Column_Value
into v_table1_eid, v_table1_dept_name
from table 1
where ename=in_emp_id;
Select eid, in_Column_value
into v_table2_eid, v_table2_dept_name
from table 2
where ename = in_emp_id;
if ( v_table2_dept_name != v_table1_dept_name) then
v_data_changed := 'Y'
Else v_data_changed :='N'
endif
return v_data_changed
end
end get_data_change;`

No comments:

Post a Comment