ALGORITHM AND PROGRAMS
ALGORITHM AND PROGRAMS
AIM:
create a table for employee details with employee number as primary key and following
fields; Name, Designation, Gender, Age, Date of Joining and Salary. Insert atleast 10
rows and perform various queries using any one comparison, logical, set, sorting and
grouping operators
ALGORITHM:
Step3 : Create table employee details with fields id, name, designation, age, gender, date of joining,
and Salary
Step5 : Use Select queries having conditional, logical, set, sorting & grouping operators
SOURCE CODE:
Name VARCHAR2(50),
Designation VARCHAR2(50),
Gender VARCHAR2(10),
Age NUMBER,
DateOfJoining DATE,
Salary NUMBER
);
INSERT INTO EmployeeDetails (EmployeeNumber, Name, Designation, Gender, Age,
DateOfJoining, Salary)
75000);
DateOfJoining, Salary)
60000);
'yyyy-mm-dd');
Group employees by designation and calculate the average salary for each group
Designation;
RESULT:
AIM:
Create tables for library management system which demonstrate the use of primary key
and foreign key. Master table should have the following fields: Accno,Title, Author and
Rate. Transaction table should have the following fields: User id, Accno, Date of Issue
and Date of Return. Create a Report with fields Accno, Title, Date of issue for the given
ALGORITHM:
Step 5: Create master table with fields Accno,Title, Author and Rate. (Accno as Primary Key)
Step 6: Create transaction table with fields : User id, Accno, Date of Issue and Date of Return.
SOURCE CODE:
Title VARCHAR2(100),
Author VARCHAR2(50),
Rate NUMBER
);
UserId NUMBER,
Accno NUMBER,
DateOfIssue DATE,
DateOfReturn DATE,
);
mm-dd'));
mm-dd'));
FROM LibraryMaster M
PROGRAM 3:
AIM:
Write a PL/SQL Program to update the rate field by 20% more than the current rate in the
inventory table which has the following fields: Product number, Product name, and rate. After
updating the table a new field called for the number of items and place for value for the new field
without using PL/SQL block.
ALGPRITHM:
step3: create product number, product name and rate into the inventory table
step4: use ALTER table to add the "number_of_items" field to the table
SOURCE CODE:
UPDATE inventory
SET rate = rate * 1.20; -- Increase the rate by 20%
UPDATE inventory
SET number_of_items = 0;
RESULT:
The given program is executed successfully
PROGRAM 4
AIM
ALGORITHM
Step3: In begin block using loop find whether string is palindrome or not
SOURCE CODE:
SET SERVEROUTPUT ON
DECLARE
str varchar2(50):='&string';
counter int:=length(str);
BEGIN
dbms_output.put_line(counter);
=substr(str,((length(str)+1)-counter),1));
counter:=counter-1;
END LOOP;
END IF;
END;
RESULT:
PROGRAM NO 5
AIM:
Write a PL/SQL program to find factorial of number using function and procedure
ALGORITHM:
Step3: in begin block using loop find the factorial of the number
SOURCE CODE:
Declare
n number;
fac number:=1;
I number
begin
n:=&n;
for i in 1..n
loop
fac:=fac*i;
end loop;
Dbms_output.put_line(‘factorial=’||fac);
end;
RESULT:
AIM:
ALGORITHM:
SOURCE CODE:
SET SERVEROUTPUT ON
emp1_name VARCHAR2(50),
last_update_time TIMESTAMP
);
BEGIN
:NEW.last_update_time := SYSTIMESTAMP;
dbms_output.put_line('emp1_id'||emp1_id);
dbms_output.put_line('emp1_name'||emp1_name);
DBMS_OUTPUT.put_line (SYSTIMESTAMP);
END;
RESULT:
PROGRAM 7
AIM:
Create Database Trigger to implement on master and transaction table which are based
ALGORITHM:
SOURCE CODE:
);
date_of_return DATE,
(product_number)
);
BEGIN
END IF;
END;
/
BEGIN
:NEW.product_number) THEN
END IF;
END;
PROGRAM 8
AIM:
Write a PL/SQL Program to split the Student table into two tables based on result (one table for
pass and another for fail ). use curser for handling records of student table.
ALGORITHM:
step3: with student values like name,ID,subjects and set Student ID as primary key
step6: In begin block using loop find the average marks for the student table
DECLARE
CURSOR student_cursor IS
SELECT *
FROM Student;
v_avg_mark NUMBER;
BEGIN
FOR student_rec IN student_cursor LOOP
v_avg_mark := (student_rec.Subject1 + student_rec.Subject2 +
student_rec.Subject3 + student_rec.Subject4 +
student_rec.Subject5) / 5;
PROGRAM 9:
AIM:
Write a PL/SQL program to raise the exception in bank account management table.
ALGORITHM:
step3: with bank account values as Account number,account holders and balance
step6: declare account balance and withdrawal amount to know whether it exceeds the balance
step7: in begin block using loop raise an exception and update the withdrawal limit
SOURCE CODE:
RESULT:
The given program is executed successfully
PROGRAM 10
AIM:
ALGORITHM:
step3: in begin block call the calculate_square function from the package
SOURCE CODE:
DECLARE
input_number NUMBER := 5;
result NUMBER;
BEGIN
-- Call the calculate_square function from the package
result := MathOperations.calculate_square(input_number);
-- Display the result
DBMS_OUTPUT.PUT_LINE('The square of ' || input_number || ' is ' || result);
END;
/
RESULT:
The given program is executed successfully
PROGRAM 11:
AIM:
Write PL/SQL cursor for referencing fields in a record.
ALGORITHM:
step1: start the program
step2: create table employee
step3: with employee values like employee ID,first name,last name salary
step4: set employee ID as primary key
step5: insert values to employee table
step6: declare a cursor for quereing data and select from employee
step7: in begin block use the cursor to fetch data into the record
step8: process the data in the record and close the cursor
step9: stop the program
SOURCE CODE:
CREATE TABLE Employee (
EmployeeID NUMBER PRIMARY KEY,
FirstName VARCHAR2(50),
LastName VARCHAR2(50),
Salary NUMBER(10, 2)
);
RESULT:
PROGRAM 12:
AIM:
ALGORITHM:
step4: creatye a trigger named"SetMark"the fires before an insert or update operation on the
"Student" table for each row
SOURCE CODE: