create or replace procedure Prc_container_booking ( p_cont_id
Varchar,p_from_cust_id varchar,p_to_cust_id varchar , p_amount number)
returns varchar
language sql
as
$$
declare
v_from_cont_id varchar;
v_from_cust_id varchar;
v_from_custstatus varchar;
v_to_cust_id varchar;
v_to_custstatus varchar;
BEGIN
select cont_id into v_from_cont_id from container_master where cont_id
= :p_cont_id;
if (v_from_cont_id is null) then
return ' Container is not available' ;
End if ;
select cust_id,cust_status into v_from_cust_id, v_from_custstatus from
customer_master where cust_id = :p_from_cust_id;
if(v_from_cust_id is null) then
return ' from customer is not available' ;
End if ;
if(v_from_custstatus = 'B') then
return ' from customer is a Blocklisted customer, we cant book it ' ;
End if ;
select cust_id, cust_status into v_to_cust_id, v_to_custstatus from customer_master
where cust_id = :p_to_cust_id;
if (v_to_cust_id is null ) then
return ' To customer is not available' ;
End if ;
if (v_to_custstatus = 'B') then
return ' To customer is a Blocklisted customer, we cant book it ' ;
End if ;
if (:p_amount < 1) then
return ' amount cannot be leess than 1' ;
End if ;
if(v_from_cust_id = v_to_cust_id) then
return ' From customer and to customer cannot be same ' ;
End if ;
insert into id_booking_dtls ( BK_ID,
BK_DT,BK_CONT_ID,BK_FROM_CUST_ID,BK_TO_CUST_ID,BK_AMT)
Values ( Bk_seq.nextval,
current_date(),:p_cont_id,:p_from_cust_id,:p_to_cust_id,:p_amount);
return ' Container Booking done';
end ;
$$;
select * from customer_master;
select * from container_master;
select * from id_booking_dtls;
call Prc_container_booking ('CONT001','CUST003','CUST004',500); -- from customer is
a Blocklisted customer, we cant book it
call Prc_container_booking('CONT002','CUST002','CUST002',200);--- From customer and
to customer cannot be same
call Prc_container_booking('CONT002','CUST002','CUST001',200);---- Container
Booking done
call Prc_container_booking ('CONT001','CUST001','CUST004',0);------ amount cannot
be leess than 1