因為要更改ERP登入的帳號名稱,也要改Employee Number,所以寫了一個PL/SQL程式,順便記錄下來。
首先建立一個暫存的表格 tmp_data,只有兩個欄位,分別是a、b,a是舊帳號、b是新帳號
create table tmp_date( a varchar2(50) , b varchar2(50) );
接著把舊帳號、新帳號寫入tmp_data。
最後執行下列的PL/SQL就可以了
declare
cursor c1 is
select a,b from tmp_data where a is not null and b is not null;
r1 c1%rowtype;
check_a number;
check_b number;
begin
for r1 in c1 loop
select count(1) into check_a from fnd_user where user_name=r1.a;
if check_a=1 then
--利用ERP本身的Package來修改帳號
fnd_user_pkg.CHANGE_USER_NAME
( x_old_user_name => r1.a, --舊的User Name
x_new_user_name => r1.b ); --新的User Name
dbms_output.put_line('User Name ,'|| r1.a ||','|| r1.b);
end if;
select count(1) into check_b from per_all_people_f where employee_number=r1.a ;
if check_b=1 then
update per_all_people_f set employee_number=r1.b where employee_number=r1.a ;
dbms_output.put_line('Employee Number , ' || r1.a || ' , ' || r1.b);
end if;
end loop ;
commit;
exception
WHEN OTHERS THEN
ROLLBACK;
commit;
DBMS_OUTPUT.PUT_LINE(SQLERRM);
end ;