Project

General

Profile

imp_loai_hang

User documentation
20/05/2025

create or replace procedure PBH_HANG_MA_HANG_NHf
    (b_ma_dvi varchar2,b_nsd varchar2,b_pas varchar2,b_oraIn clob)
AS
    b_loi varchar2(1000); b_i1 number; b_lenh varchar2(1000);
  a_ma pht_type.a_var; a_ten pht_type.a_var; a_tc pht_type.a_var; a_ma_ct pht_type.a_var;
    a_ngay_bd pht_type.a_num; a_ngay_kt pht_type.a_num; a_mrr pht_type.a_var;
begin
-- Dan
b_loi:=FHT_MA_NSD_KTRA(b_ma_dvi,b_nsd,b_pas,'BH','MA','M');
if b_loi is not null then raise PROGRAM_ERROR; end if;
b_lenh:=FKH_JS_LENH('ma,ten,tc,ma_ct,ngay_bd,ngay_kt,mrr');
EXECUTE IMMEDIATE b_lenh bulk collect into a_ma,a_ten,a_tc,a_ma_ct,a_ngay_bd,a_ngay_kt,a_mrr using b_oraIn;
for b_lp in 1..a_ma.count loop
  if trim(a_ma(b_lp)) is null then b_loi:='loi:Nhap ma:loi'; raise PROGRAM_ERROR; end if;
  if trim(a_ten(b_lp)) is null then b_loi:='loi:Nhap ten:loi'; raise PROGRAM_ERROR; end if;
  a_ma_ct(b_lp):=nvl(trim(a_ma_ct(b_lp)),' ');
  if a_ma_ct(b_lp) = ' ' then a_tc(b_lp):= 'T';
  else a_tc(b_lp):= 'C';
  end if;
  a_tc(b_lp):=nvl(trim(a_tc(b_lp)),'C');
  if a_ma_ct(b_lp)<>' ' then
    b_loi:='loi:Sai ma cap tren:loi';
    if a_ma(b_lp)=a_ma_ct(b_lp) then raise PROGRAM_ERROR; end if;
    select 0 into b_i1 from bh_hang_loai where ma=a_ma_ct(b_lp) and tc='T';
  end if;
  a_mrr(b_lp):=nvl(trim(a_mrr(b_lp)),'1');
  if a_ngay_bd(b_lp) in(0,30000101) then a_ngay_bd(b_lp):=PKH_NG_CSO(sysdate); end if;
  a_ngay_kt(b_lp):=nvl(a_ngay_kt(b_lp),0);
  if a_ngay_kt(b_lp)=0 then a_ngay_kt(b_lp):=30000101; end if;
  b_loi:='';
  delete bh_hang_loai where ma=a_ma(b_lp);
  insert into bh_hang_loai values(b_ma_dvi,a_ma(b_lp),a_ten(b_lp),a_ma_ct(b_lp),a_tc(b_lp),a_mrr(b_lp),a_ngay_bd(b_lp),a_ngay_kt(b_lp),b_nsd,'"'||b_oraIn||'"');
end loop;
commit;
exception when others then if b_loi is null then raise PROGRAM_ERROR; else raise_application_error(-20105,b_loi); end if;
end;
 

Files