create or replace editionable procedure PBH_XE_PB_TSO(
b_ma_dvi varchar2,b_nsd varchar2,b_pas varchar2,b_oraIn clob,b_oraOut out clob)
AS
b_loi varchar2(100); b_i1 number; b_lenh varchar2(2000); cs_lke clob:='';
b_hang varchar2(20); b_hieu varchar2(20); b_ma varchar2(20);
begin
-- Dan
b_loi:=FHT_MA_NSD_KTRA(b_ma_dvi,b_nsd,b_pas,'BH','MA','X');
if b_loi is not null then raise PROGRAM_ERROR; end if;
b_lenh:=FKH_JS_LENH('ma,hang,hieu');
EXECUTE IMMEDIATE b_lenh into b_ma,b_hang,b_hieu using b_oraIn;
if b_hang is null or b_hieu is null or b_ma is null then
b_loi:='loi:Nhap hang, hieu, phien ban:loi'; raise PROGRAM_ERROR;
end if;
select count(*) into b_i1 from bh_xe_pb where hang=b_hang and hieu=b_hieu and ma=b_ma;
if b_i1<>0 then
select json_object(ttai,so_cn,csuat,dco,
'dong' value FBH_XE_DONG_TENl(dong),'loai_xe' value FBH_XE_LOAI_TENl(loai_xe)) into cs_lke
from bh_xe_pb where hang=b_hang and hieu=b_hieu and ma=b_ma;
end if;
select json_object('cs_lke' value cs_lke) into b_oraOut from dual;
exception when others then if b_loi is null then raise PROGRAM_ERROR; else raise_application_error(-20105,b_loi); end if;
end;