|
ProductsByCustomer
|
|
Procedure body ProductsByCustomer(Customer_Id NUMBER), Package PRODUCTS
Name
|
Datatype
|
Precision
|
Description
|
Customer_Id
|
NUMBER
|
|
NUMBER, parameter of PRODUCTS.ProductsByCustomer
|
Name
|
Types
|
Value
|
Cust_fname
|
Variable
|
|
|
Cust_lname
|
Variable
|
|
|
customer_list
|
Variable
|
|
|
prod_name
|
Variable
|
|
|
Prod_num
|
Variable
|
|
|
prod_size
|
Variable
|
|
|
product_list
|
Variable
|
|
|
r1
|
Variable
|
|
|
Name
|
Definition
|
c1
|
cursor c1 is SELECT product.id Pid, product.name prod_name, sum (sales_order_items.quantity*unit_price) Pamount FROM customer, product, sales_order_items, sales_order WHERE ( customer.id = Customer_Id ) and ( customer.id = sales_order.cust_id ) and ( sales_order_items.id = sales_order.id)and (pid = sales_order_items.prod_id) GROUP BY Pid;
|
procedure ProductsByCustomer(Customer_Id in NUMBER )
is
Cust_fname varchar2(50);
Cust_lname varchar2(50);
prod_name varchar2(50);
prod_size varchar2(50);
Prod_num NUMBER;
type customers_typ is table of varchar2(150) index by binary_integer;
type products_typ is table of varchar2(150) index by binary_integer;
cursor c1 is
SELECT product.id Pid,
product.name prod_name,
sum (sales_order_items.quantity*unit_price) Pamount
FROM customer,
product,
sales_order_items,
sales_order
WHERE ( customer.id = Customer_Id ) and
( customer.id = sales_order.cust_id ) and
( sales_order_items.id = sales_order.id)and
(pid = sales_order_items.prod_id)
GROUP BY Pid;
customer_list customers_typ;
product_list products_typ;
begin
select fname, lname
into Cust_fname, Cust_lname
from customer
where id = Customer_Id ;
If Cust_fname is null Or Cust_fname = '' Then
Employees.DeleteEmployeeById(Customer_Id);
End If;
SELECT Count(*)
into Prod_num
FROM customer,
product,
sales_order_items,
sales_order
WHERE ( customer.id = Customer_Id ) and
( customer.id = sales_order.cust_id ) and
( sales_order.id = sales_order_items.id )and
(product.id = sales_order_items.prod_id)
GROUP BY product.id;
select fname, lname, name, prod_size
into cust_fname, cust_lname, prod_name, prod_size
from all_customers, all_products
where all_customers.id = Customer_Id ;
dbms_output.put_line('-------------------------------------');
dbms_output.put_line(
'Product list ' || Data.uf_SetBracket(TO_CHAR(Prod_num)) || ' for the customer : ' ||
Customers.GetFullName(Cust_fname, Cust_lname) ||
to_char(sysdate,'dd-Mon hh24:mi:ss')
);
dbms_output.put_line('-------------------------------------');
dbms_output.put(
lpad('Product name',25) ||
lpad('Product amount',12)
);
dbms_output.new_line;
dbms_output.new_line;
for r1 in c1 loop
dbms_output.put_line(
lpad(r1.prod_name,25) ||
r1.Pamount
);
end loop;
If Cust_fname = '' Then
Data.sp_deleteemployee(Customer_Id);
End If;
dbms_output.put_line('-------------------------------------');
dbms_output.put_line(
'Product list ' || Data.uf_SetBracket(TO_CHAR(Prod_num)) || ' for the customer : ' ||
Customers.GetFullname(Cust_fname, Cust_lname) ||
to_char(sysdate,'dd-Mon hh24:mi:ss')
);
dbms_output.put_line('-------------------------------------');
dbms_output.put(
lpad('Product name',25) ||
lpad('Product amount',12)
);
dbms_output.new_line;
dbms_output.new_line;
for r1 in c1 loop
dbms_output.put_line(
lpad(r1.prod_name,25) ||
r1.Pamount
);
end loop;
select fname,
lname,
all_products.name,
all_products.prod_size,
all_products.id,
product.name
into cust_fname,
cust_lname,
prod_name,
prod_size
from all_customers,
all_products,
product
where all_customers.id = Customer_Id
and product.id = all_products.id
and prod_size > '36';
dbms_output.put_line('-------------------------------------');
dbms_output.put_line(
'Product list ' || Data.uf_SetBracket(TO_CHAR(Prod_num)) || ' for the customer : ' ||
Customers.GetFullname(Cust_fname, Cust_lname) ||
to_char(sysdate,'dd-Mon hh24:mi:ss')
);
dbms_output.put_line('-------------------------------------');
dbms_output.put(
lpad('Product name',25) ||
lpad('Product amount',12)
);
dbms_output.new_line;
dbms_output.new_line;
for r1 in c1 loop
dbms_output.put_line(
lpad(r1.prod_name,25) ||
r1.Pamount
);
end loop;
select fname,lname,
all_products.name, all_products.prod_size,
all_products.id, product.name
into cust_fname, cust_lname,
prod_name, prod_size
from all_customers,
all_products,
product
where all_customers.id = Customer_Id
and product.id = all_products.id
and prod_size < '37';
If Cust_fname is null Or Cust_fname = ''
Then
sp_deleteemployee(Customer_Id);
End If;
end ProductsByCustomer