Assignment 01 CSE464
Assignment 01 CSE464
Submitted To:
Submitted By:
Student name: Anannya Das
Student ID: 2016-2-60-135
Date of Submission: 5/12/2022
1. (Basic Table Manipulation) Write a program that declares an integer variable called num,
assigns a value to it, and computes and inserts into the tempp table the value of the variable
itself, its square, and its cube. Consider the following DDL statements to create tempp table.
Answer:
TABLE created.
BEGIN
END;
Enter value
FOR num: 5
SELECT *
FROM tempp;
-- 5 25 125
2. (Conditional Statements) Input three positive integers representing the sides of a triangle, and
determine whether they form a valid triangle. Hint: In a triangle, the sum of any two sides must
always be greater than the third side. Display the output on the screen using
dbms_output.put_line.
Answer:
b number := &second_side;
c number := &third_side;
dbms_output.put_line('valid triangle');
END IF;
END IF;
END IF;
END;
3. (Conditional Statements) Program should accept the age of the user. Depending upon the
Answer:
DECLARE age number:=&user_age;
USER varchar(20);
END IF;
dbms_output.put_line('user is '||USER);
END;
4. (Conditional Statements) Suppose the grade obtained by a student depends upon his scores
and
Scores Grades
95-100 A
70-84 B
70-84 C
60-69 D
0-59 F
Write a PL/SQL block to accept a student‟s marks and accordingly output his grade. Display the
Answer:
END IF;
END;
Product Code
Computer Stationery 1
Fixed Disks 2
Computers 3
Write a program to accept the order details i.e. product code and order amounts for the products,
calculate the discount amounts as per this policy and output the net order amount. Display the
Answer:
disc number;
prod varchar2(30);
END IF;
END IF;
END IF;
END IF;
dbms_output.put_line('_____________________________');
dbms_output.put_line('PRODUCT '||prod);
dbms_output.put_line('DISCOUNT IS '||disc);
dbms_output.put_line('AFTER DISCOUNT'||((1-disc)*amt));
dbms_output.put_line('______________________________');
END;
6. (Iteration) Write a program that examines all the numbers from 1 to 999, displaying all those
for which the sum of the cubes of the digits equal the number itself. Display the output on the
screen using dbms_output.put_line.
Answer:
x int;
y int;
z int;
y := mod(i,10);
z := mod(i,10);
dbms_output.put_line ('____');
END IF;
i := i + 1;
END LOOP;
END;
7. (Procedure) The CUSTOMER table of a state electricity board consists of the following
fields:
Meter_Number varchar2(4)
Meter_Type char(1)
Previous_Reading Number
Current_Reading Number
Customer_Type char(1)
Formulae used:
Write a procedure calculate_bill to calculate the bill for each customer. Consider the following
Meter_Number varchar2(4),
Meter_Type char(1),
Previous_Reading number,
Current_Reading number,
Customer_Type char(1),
Last_Bill_payment char(1),
);
After calculating the bill, the procedure should insert the total Amount, Surcharge, Excise and
units number,
rate number,
amount number,
surcharge number,
Excise number,
Net number
);
Answer:
customer%rowtype;
v_bill bill%rowtype;
CURSOR c1 IS
SELECT *
FROM customer;
units’ number;
amount number;
surcharge number;
Excise number;
Net number;
BEGIN
DELETE
FROM bill;
SELECT decode (v_customer."Customer Type", 'A', 1, 'I', 1.25, 'C', 1.50, 'R', 1.30) INTO rate
FROM dual;
SELECT decode (v_customer."Meter Type", 'T', 10, 'S', 5) INTO surcharge
FROM dual;
amount := rate*units;
surcharge := surcharge*amount;
END LOOP;
END;
OUTPUT
--Compile:
--Call:
EXEC calculatebill
8. (Exception) Write a PL/SQL block that prompts the user to enter the salary of an employee.
Your program should display the name of the employee (from the EMP table as shown below)
who‟s getting that salary. If more than 1 employee is receiving that salary, or if no employees
exist getting that salary, your program should display appropriate messages. Use too_many_rows
and no_data_found exceptions to achieve this. Display the results on the screen using
dbms_output.put_line.
Answer:
BEGIN
FROM emp
exception WHEN too_many_rows THEN dbms_output.put_line ('too many data found in result
can't handel ');
WHEN no_data_found THEN dbms_output.put_line ('no data found for your query');
END;
If any employee has experience less than 2 years, the program should be aborted with a suitable
message. Raise the user-defined exception exp_check to achieve this. Display the results on the
CURSOR c1 IS
FROM emp;
BEGIN
FOR i IN c1 LOOP
ELSE
END IF;
END LOOP;
END;
10. (Function) Write a PL/SQL function to take three parameters, the sides of a triangle. The
sides of the triangle should be accepted from the user. The function should return a Boolean
value – true if the triangle is valid, false otherwise. A triangle is valid if the length of each side is
less than the sum of the lengths of the other two sides. Check if the dimensions entered by the
user can form avalid triangle.
Display the results on the screen using dbms_output.put_line.
Answer:
BEGIN
END IF;
RETURN FALSE;
END;
CALLING-CODE
b number: =&side2;
c number := &side3;
x boolean;
BEGIN
x := triangle(a,b,c);
END /
Enter value
NEW 2: a number := 2;
Enter value
NEW 3: b number := 3;
Enter value
NEW 4: c number := 5;