You are on page 1of 10

1.

Employee Information

Aim:

To create an employee table and retrieve records using Oracle SQL Plus.

Algorithm

Step 1: Click  Start  All Programs  SQL PLUS

Step 2: Create table named employee with the required fields using query.

create table employee(empname varchar(15),empcode number(6) primary key,


address varchar(25),designation varchar(15),grade varchar(1),dateofjoin date,salary number (13,2));
Step 3: Insert the records into employee table using query

insert into employee values(‘rani’,101,’coimbatore’,’manager’,’A’,’15-dec-2018’,50000);

Step 4: Display all the records of employee table using query

Select * from employee;

Step 5: Display name of the employees whose salary is greater than “10000” using query

select * from employee where salary > 10000;

Step 6: Display the details of employees in ascending order according to employee code

select * from employee order by empcode;

Step 7: Display the total salary of the employees whose grade is “A” using query

select sum(salary) from employee where grade = 'A';

Step 8: End

Result:

Thus the above program has been executed successfully and output is verified
2. Payroll System

Aim:

To create payroll table and retrieve records using Oracle SQL Plus.

Algorithm

Step 1: Click  Start  All Programs  SQL Plus

Step 2: Create table named payroll with the required fields using query.

create table payroll(empno number(8) primary key, empname varchar(15),


department varchar(10),basicpay number(11,2), hra number(9,2), da number(9,2), pf number(9,2),
netpay number(11,2));
Step 3: Insert the records into payroll table using query
insert into payroll values(101,‘rani’,’manager’,’A’,’15-dec-2018’,50000);

Step 4: Display all the records of employee table using query


Select * from employee;

Step 5: Update the records to calculate the netpay


Update payroll set netpay=basicpay+hra+da-pf;

Step 6: Arrange the records of employees in ascending order of their netpay


select * from payroll order by netpay;

Step 7: Display the details of the employees whose department is sales


Select * from payroll where department=’sales’;

Step 8: Select the details of employees whose HRA >=1000 and DA<=900
Select * from payroll where hra >=1000 and da<=900;

Step 9: Select the records in descending order


Select * from payroll order by netpay desc;

Step 10: End


Result:

Thus the above program has been executed successfully and output is verified
3. Product Details

Aim:
To create product table and retrieve records using Oracle SQL Plus.
Algorithm
Step 1: Click  Start  All Programs  SQL Plus
Step 2: Create table named product with the required fields using query.
create table product(prodno number(6), pname varchar2(15), unitmeasure varchar2(15), unitprice number(4,2),
quantity number(6,2), amount number(8,2));

Step 3: Insert the records into product table using query

Insert into product values (&prodno,'&pname','&unitmeasure',&unitprice,&quantity,&amount);


Enter value for prodno: 1000
Enter value for pname: rice
Enter value for unitmeasure: kg
Enter value for unitprice: 50
Enter value for quantity: 2
Enter value for amount: 0

Step 4: Display all the records of product table using query


Select * from product;

Step 5: Using update statements calculate the total amount and then select the record.
Update product set amount=unitprice*quantity;

Step 6: Select the records whose unit of measure is “Kg”


Select * from product where unitmeasure='kg';

Step 7: Select the records whose quantity is greater than 10 and less than or equal to 20.
select * from product where quantity > 10 and quantity <= 20;

Step 8: Calculate the total amount by using sum operation


select sum(amount) from product;

Step 9: Calculate the number of records whose unit price is greater than 50 with count
operation.
select count(*) from product where unitprice > 50;

Step 10: End

Result:

Thus the above program has executed successfully and output is verified.
4. Sales Order

Aim:

To create sales_order and salesorder_product table and retrieve records using Oracle SQL Plus.

Algorithm

Step 1: Click  Start  All Programs  SQL Plus

Step 2: Create table named sales_order with the required fields using query.

Create table sales_order(sorder_no number(3) primary key,clientno number(3), delivery_address


varchar2(30), delivery_date date, order_status varchar2(10));

Step 3: Create table named salesorder_product with the required fields using query.

Create table salesorder_products(sorder_no number(3),productid number(3) primary key, quantity


number(3),unitprice number(6,2),amount number(7,2));

Step 4: Add new column for storing salesman number using ALTER command
Alter table sales_order add salesman_no number(3);
Step 5: Set the sorder_no as foreign key as column constraints
alter table salesorder_products add foreign key(sorder_no) references sales_order(sorder_no);
Step 6: Enforce the integrity rules using CHECK
alter table sales_order add check(salesman_no >= 1 and salesman_no <=50);
Step 7: End

Result:
Thus the above program has been executed successfully and output is verified.
5. Student Information Using PL/SQL

Aim:

To create student table in SQL and to find total, average and result using PL/SQL

Algorithm

Step 1: Click  Start  All Programs  SQL PLUS

Step 2: Create table named student with the required fields using query.

SQL> create table student5(rollno number(5) primary key,name varchar2(20),oracle number(3),brm


number(3),accounts number(3),gbe number(3),total number(3),average number(6,2),result
varchar2(5));

Step 3: Insert the records into student table using query

SQL> insert into student5 values(100,’ raja’, 70, 89, 73,90,0,’’);

Step 4: In PL/SQL, write the code to find total , average and result of student and also update the
student table.

Step 5: Run the PL/SQL program in SQL

Step 6: End

Result:

Thus the above program have been executed successfully and output is verified
6. Electricity Bill

Aim:

To create electricity bill using PL/SQL block.

Algorithm

Step 1: Open Notepad to write PL/SQL block

Step 2: Declare the variables consumer no,name,previous reading, current reading, number of unit and
amount

Step 3: Get the values of consumer no,name , previous reading and current reading

Step 4: Calculate the number of unit consumed = current reading – previous reading

Step 5: Calculate the electricity bill amount using tariff rules.

Step 6: Run the PL/SQL program in SQL

Step 7: End

Result:

Thus the above program have been executed successfully and output is verified
7. Splitting Table

Aim:

To split the student information table into two, one with the passes and other with the failed.
Algorithm

Step 1: Click  Start  All Programs  SQL PLUS

Step 2: Create table named student with the required fields using query.

SQL> create table sristudent(rollno number(3),name varchar2(30),m1 number(3), m2 number(3), m3


number(3), total number(3),result varchar2(6));
Step 3: Insert the records into student table using query

SQL> insert into sristudent values(100,’kavitha’,90,97,56,0,’’);

Step 4: Create table named studentpass with the required fields using query.

SQL> create table studentpass(rollno number(3),name varchar2(30),m1 number(3), m2 number(3), m3


number(3), total number(3),result varchar2(6));
Step 5: Create table named studentfail with the required fields using query.

SQL> create table studentfail(rollno number(3),name varchar2(30),m1 number(3), m2 number(3), m3


number(3), total number(3),result varchar2(6));
Step 6: In PL/SQL, create cursor for selecting all records of student table

Step 7: Retrieve each record from cursor using For Loop.

Step 8 : Write the code to find total and result of current student and update the student table.

Step 9: if result=’pass’ then insert the corresponding record in studentpass table. Otherwise insert the
corresponding record in studentfail table.

Step 10: Run the PL/SQL program in SQL

Step 11: End

Result:

Thus the above program have been executed successfully and output is verified
8. Joining Table

Aim:

To join two tables: First table contains rollno,name and total mark and Second table contains the rollno
and address

Algorithm

Step 1: Click  Start  All Programs  SQL PLUS

Step 2: Create table named studentmark with the required fields rollno as primary key,name and total
mark.

SQL> create table studentmark(rollno number(3) primary key,name varchar2(15),total number(3));


Step 3: Create table named personal with the required fields rollno as foreign key, and address

SQL> create table personal(rollno number(3) references studentmark(rollno),address varchar2(40));


Step 4: Create table named studentdetail with the required fields rollno,name,total and address

SQL> create table studentdetail(rollno number(3),name varchar2(15),total number(3),address


varchar2(40));
Step 5: Insert the records into studentmark table using query

SQL> insert into studentmark values(100,'kavi',600);


Step 6: Insert the records into perosnal table using query

SQL> insert into personal values(203,'madurai');


Step 7: In PL/SQL, create cursor for selecting all records from studentmark and personal table

Step 8: Retrieve each record from cursor using For Loop and insert records in studentdetail table

Step 9: Run the PL/SQL program in SQL

Step 10: End

Result:

Thus the above program have been executed successfully and output is verified
9 (a). Factorial Using Recursion

Aim:

To find factorial using recursion in PL/SQL block.

Algorithm

Step 1: Open Notepad to write PL/SQL block

Step 2: Create function fact to find factorial using recursive calls

Step 3 : Run the function fact in SQL

Step 4: Create another PL/SQL block factorial to call the function fact.

Step 5: In factorial block, Declare the variables n and f.

Step 6: Get the value of n

Step 7: Call the function fact with parameter n using f := fact(n)

Step 8: Display the value of f.

Step 9: Run the factorial PL/SQL program in SQL

Step 10: End

Result:

Thus the above program have been executed successfully and output is verified
9 (b). Fibonacci Series Using Recursion

Aim:

To generate Fibonacci series using recursion in PL/SQL block.

Algorithm

Step 1: Open Notepad to write PL/SQL block

Step 2: Create function fibo to find Fibonacci value using recursive calls

Step 3 : Run the function fibo in SQL

Step 4: Create another PL/SQL block fibonacci to call the function fibo.

Step 5: In fibonacci block, Declare the variables n and f.

Step 6: Get the value of n

Step 7: Call the function fibo with parameter n using f := fibo(n)

Step 8: Display the value of f.

Step 9: Run the factorial PL/SQL program in SQL

Step 10: End

Result:

Thus the above program have been executed successfully and output is verified

You might also like