SQL Practical
SQL Practical
Fieldname Type
RR_number varchar2(10)
Consumer_name varchar2(25)
Date_billing date
Units number (4)
Ans: Create table Ebill11 (rr_number varchar2 (10), consumer_name varchar2 (25),
date_billing date, units number (4));
e) Compute the result as “pass” or fail by checking if the student has scored more
than 35 marks in each subject.
Ans: alter table student12 add(result varchar2(10));
update student set result=’pass’ where sub1>=35 and sub2>=35 and sub3>=35;
l) Count the number of students who have percentage more than 60.
Ans: select count(*) from student where per>=60;
EXPERIMENT NO:3
Generate the employee details and compute the salary based on the department
Create the following table employee
Field name Data type Description
Empid number(4) employee’s id number
Deptid number(2) department’s id
number
Empname varchar2(25) employee name
Empsalary number(5) salary of the employee
Enter 10 rows of data for table employee and 4 rows of data for department
table
EMPLOYEE TABLE
10 rows selected
Create another table department with the following structure
Field name Data type Description
Deptid number(2) department’s id
number
Deptname varchar2(15), department name
Supervisor varchar2(15), department head’s
name
Assume the department names as purchase(id-01),accounts(id-02),sales(id-
03),apprentice(id-04)
DEPARTMENT TABLE
SQL> create table department(deptid number(2),deptname
varchar2(15),supervisor varchar2(15));
Table created.
COUNT(*)
---------------
4
5. Retrieve the department names for each department where only one
employee works.
SQL> select deptname from department where deptid=(select deptid from
employee group by deptid having count(*)=1);
DEPTNAME
----------------
Purchase
10 rows selected.
2 rows deleted.
EXPERIMENT NO: 4
Create database for the bank transaction.
Create the following table customer
Field name Data type Description
Cno varchar2(4) customer number
Cname varchar2(25) customer name
caddress varchar2(25) customer address
Cphone varchar2(12) customer phone
number
7. To display all records from bank whose transaction date is greater than or
equal to 01-mar-2014.
SQL> select * from bank where trdate>='01-mar-2014';
ACCN TRAMT TRDATE TRTYPE CNO
--------- ------------- ------------------- -------------- -----------
1310 70000 26-MAR-14 credit 100
1320 23961.75 01-MAR-14 debit 100
1350 25091.25 11-MAR-14 debit 103
8. To join two tables.
CNO VARCHAR2(4)
CNAME VARCHAR2(25)
CADDRESS VARCHAR2(20)
CPHONE VARCHAR2(12)
13. Delete records from bank having an account number 1340
1 row deleted.
14. Create a table containing customer number ranging from 100 to 102
SQL> create table tempcustomeras(select * from customer where cno between
100 and 102);
Table created.
15. Display records from customer whose name starts with ‘g’
SYSDATE
---------
28-AUG-18
SUM(TRAMT)
----------
189053
View created.
CNO CPHONE
---- ------------
100
101 9876024561
102 9535879022
CNO
----
100
102
103
20. Display account number from bank who have more than one
transaction
ACCN COUNT(*)
---- ----------
1310 2
21. Display all records from customer whose phone number is NULL
3 rows deleted.
23. Drop table bank.
Table dropped.
Table dropped.