以下函数编译得很好。但是当调用匿名 PL/SQL 代码中的函数时,调用会失败。谁能建议为什么?我正在尝试插入不匹配的(新)数据并更新匹配的(现有)数据。
Function Fn_Insert_Data_Using_Merge (p_Id in Number,
p_fname in varchar2,
p_mname in varchar2,
p_lname in varchar2,
p_birth_date in date) Return Boolean
Is
Begin
Dbms_Output.put_line ('Inside the function Fn_Insert_Data_Using_Merge ...');
Merge Into test_employee te
using (select distinct p_Id, p_fname, p_mname, p_lname, p_birth_date
from test_employee) temp_data
on (te.first_name = temp_data.p_fname and
te.middle_name = temp_data.p_mname and
te.last_name = temp_data.p_lname)
when matched then
update
set first_name = p_fname,
middle_name = p_mname,
last_name = p_lname,
run_status = 'Updated'
when not matched then
insert (id, first_name, middle_name, last_name, birth_date, run_status)
values
(p_id, p_fname, p_mname, p_lname, p_birth_date, 'Inserted');
Dbms_Output.put_line ('Returning successfully from the function Fn_Insert_Data_Using_Merge ...');
Return True;
Exception
When Dup_Val_On_Index Then
Dbms_Output.put_line ('The name already exists...Cannot insert again ..');
Return False;
When Others Then
Dbms_Output.put_line ('Facing some critical error : ' || SQLERRM);
Return False;
End Fn_Insert_Data_Using_Merge;