I have 2 tables with same set Column Name (52+ coulmns) . I need to write an Oracle function to compare whether any records get changed between these columns. EMP_ID is the primary Key
I'm trying to use the below function, but it is giving me incorrect result, I'm 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_Name varchar2)
return char is
v_data_changed char;
begin
select eid, in_Column_Name
into v_table1_eid, v_table1_Column_Value
from table 1
where eid=in_emp_id;
Select eid, in_Column_Name
into v_table2_eid, v_table2_Column_Value
from table 2
where eid = in_emp_id;
if ( v_table2_Column_Value != v_table1_Column_Value)
then
v_data_changed := 'Y'
else
v_data_changed :='N'
endif
return v_data_changed
end
end get_data_change;