Tuesday, 25 August 2015

Loading data to table through txt file and updating description in fnd_user table

Loading data to table through txt file and updating description column in fnd_user table

create table user_data(
sno  number(4),
sname varchar2(30));

create sequence W2
start with 1
increment by 1;

Loading data:

load data
infile 'd:\user_desc.txt'
truncate into table user_data
fields terminated by ','
Trailing nullcols
(sno "w1.nextval",sname)

select * from user_data;

Checking purpose:

declare
vsno user_data.sno%type;
vsname user_data.sname%type;
i number(3);
begin
i:=1;
loop
exit when i>100;
select sno,sname into vsno,vsname from user_data
where sno=i;
Begin
select User_name from fnd_user where user_name=vsname;
dbms_output.put_line('employee found'||user_name);
when No_data_found then
dbms_output.put_line('employee not found');
end
i:=i+1;
end loop;
end;

create or replace procedure update_userdesc
as
i number(4);
vsno user_data.sno%type;
vsname user_data.sname%type;
begin
i:=1;
loop
exit when i>100;
select sno,sname into vsno,vsname from user_data
where sno=i;
update fnd_user set description = concat((select description from fnd_user where user_name=vsname),' - IT - Service Desk Agents'),
last_update_date=sysdate,last_updated_by='14120',last_update_login='*****'
where user_name=upper(vsname);
i:=i+1;
end loop;
commit;
end;

exec update_userdesc;
select a.description,b.sname from fnd_user a,user_data b
where a.user_name=b.sname;