This repository was archived by the owner on Apr 14, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDMS.sql
More file actions
70 lines (63 loc) · 2.02 KB
/
Copy pathDMS.sql
File metadata and controls
70 lines (63 loc) · 2.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
set serveroutput on
#To calculate the profit or loss for a given date:
create or replace function profitday(dat sales.sales_date %type) return varchar2 as
profit sales.sales %type;
loss sales.cost %type;
cos sales.sales %type;
sal sales.sales %type;
exp exception ;
begin
select sales into sal from sales where sales_date = dat;
select cost into cos from sales where sales_date = dat;
if (sal > cos) then
profit := sal -cos;
dbms_output.put_line('The profit on '||dat||' is = '||profit);
elsif(cos > sal) then
loss := cos - sal;
dbms_output.put_line('The loss on '||dat||' is = '||loss);
else
raise exp;
end if;
return 'success';
exception when exp then
dbms_output.put_line('no profit no loss' );
end;
/
#To calculate the whole year profit and loss
create or replace procedure pro_loss as
profit sales.sales %type;
loss sales.sales %type;
cos number ;
sale number;
begin
select sum(sales.sales ) into sale from sales ;
select sum(sales.cost) into cos from sales;
if (sale > cos ) then
profit := sale-cos;
dbms_output.put_line('The profit of one year is = '||profit);
else
loss := cos - sale;
dbms_output.put_line('The loss of one year is = '||loss);
end if;
end;
/
#To calculate maximum product sold in a year:
create or replace procedure max_pro_sale as
max_quantity v1.quantity1 %type;
product v1.product_code %type;
begin
select max(quantity1) into max_quantity from v1;
select product_code into product from v1 where quantity1 = max_quantity;
dbms_output.put_line('The maximum production sale in year is of product '||product||' having quantity '||max_quantity);
end;
/
#To calculate minimum product sold in a year:
create or replace procedure min_pro_sale as
min_quantity v1.quantity1 %type;
product v1.product_code %type;
begin
select min(quantity1) into min_quantity from v1;
select product_code into product from v1 where quantity1 = min_quantity;
dbms_output.put_line('The minimum production sale in year is of product '||product||' having quantity '||min_quantity);
end;
/