You are on page 1of 2

-- Created on 10/1/2013 by VIJENDRA.

KUMAWAT
declare
-- Local variables here
vl_dac_name san_dac_master.dac%type := 'CJAI 12';
vl_ao_name san_ao_master.ao_name%type := 'JAI-2';
type array_t is varray(2) of varchar2(50);
vl_district_array array_t := array_t('Jaipur', 'Alwar');
vl_dac_record san_dac_master%rowtype;
vl_dac_exists number := null;
vl_dac_district_rltn_record san_dac_district_rltn%rowtype;
P_ERROR_CODE VARCHAR2(2000);
P_ERROR_MSG VARCHAR2(2000);
begin
-- fetching next sys_Dac_id from sequence
select count(*)
into vl_dac_exists
from san_dac_master
where upper(dac) = upper(vl_dac_name);
if vl_dac_exists = 1
then
dbms_output.put_line ('Dac already exists with given name : '||vl_dac_name);
raise_application_error(-20101, 'Dac already exists with given name : '||vl_da
c_name);
end if;
select seq_san_dac_master.nextval into vl_dac_record.sys_dac_id from dual;
dbms_output.put_line ('New sys_dac_id : '|| vl_dac_record.sys_dac_id);
select sys_ao_id into vl_dac_record.sys_ao_id from san_ao_master where upper(a
o_name) = upper(vl_ao_name);
dbms_output.put_line (' sys_ao_id : '|| vl_dac_record.sys_ao_id);
vl_dac_record.created_by := 'Ashish Garg';
vl_dac_record.creation_date := sysdate;
vl_dac_record.dac := upper(vl_dac_name);
vl_dac_record.status := '1';
vl_dac_record.assigned_to_am := '0';
vl_dac_record.assigned_to_zm := '0';
vl_dac_record.assigned_to_bm := '0';
vl_dac_record.assigned_to_head_cac_rac_ssd := '0';
vl_dac_record.assigned_to_head_cac_rac := '0';
insert into san_Dac_master values vl_dac_record;
dbms_output.put_line ('Record inserted in san_dac_master table');
-- inserting record in san_dac_district_rltn table
dbms_output.put_line ('Number of district covered in given dac : '||vl_distri
ct_array.count);
for i in 1..vl_district_array.count loop
dbms_output.put_line ('District : '||vl_district_array(i));
select sys_district_id
into vl_dac_district_rltn_record.sys_district_id
from san_district_master
where upper(district) = upper(vl_district_array(i));
dbms_output.put_line ('sys_district id : '|| vl_dac_district_rltn_record.s
ys_district_id ||' for district : '||vl_district_array(i));
vl_dac_district_rltn_record.sys_dac_id := vl_dac_record.sys_dac_id;
vl_dac_district_rltn_record.status := '1';
insert into san_dac_district_rltn values vl_dac_district_rltn_record;
dbms_output.put_line ('inserted record in san_dac_district_rltn table');

end loop;
commit;
pkg_sankhya.proc_san_rptg_geo_dim(p_error_code => p_error_code,
p_error_msg => p_error_msg);
pkg_sankhya.proc_san_rptg_trtry_dim(p_error_code => p_error_code,
p_error_msg => p_error_msg);
dbms_output.put_line ('applied commit. program end');
exception
when others then
rollback;
dbms_output.put_line ('Error : '||sqlerrm);
end;