We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10
1.
Generate the Electricity Bill for consumers
1. SQL>create table ebill(meter_no varchar(10),c_name NAME TYPE
varchar(25),bill_date date,units number(4)); METER_NO VARCHAR2(10) o/p : Table created C_NAME VARCHAR2(25) 2. SQL>insert into ebill values(‘e1’,’Karth’,’17-dec-2019’,45); BILL_DATE DATE o/p : 1 row created 3. SQL>insert into ebill values(‘e2’,’Renu’,’8-dec-2019’,46); UNITS NUMBER(4) o/p : 1 row created 4. SQL>insert into ebill values(‘e3’,’Anu’,’9-dec-2019’,47); 13.SQL>alter table ebill add(bill_amt number(6,2),due_date o/p : 1 row created date); 5. SQL>insert into ebill values(‘e4’,’Adit’,’10-dec-2019’,48); o/p : Table altered o/p : 1 row created 14.SQL>update ebill set bill_amt=50; 6. SQL>insert into ebill values(‘e5’,’Nithu’,’11-dec-2019’,49); o/p : 10 rows updated o/p : 1 row created 15.SQL>update ebill set bill_amt = bill_amt + 4.50 + 7. SQL>insert into ebill values(‘e6’,’Ash’,’12-dec-2019’,51); (units-100) * 5.50 where units>100; o/p : 1 row created o/p : 5 rows updated 8. SQL>insert into ebill values(‘e7’,’Ravi’,’13-dec-2019’,52); 16.SQL>update ebill set bill_amt=bill_amt+units*4.50 where o/p : 1 row created units<=100; 9. SQL>insert into ebill values(‘e8’,’Mithu’,’14-dec-2019’,53); o/p : 5 rows updated o/p : 1 row created 17.SQL>update ebill set due_date=bill_date+15; 10.SQL>insert into ebill values(‘e9’,’Megha’,’15-dec-2019’,54); o/p : 10 rows updated o/p : 1 row created 18.SQL>select *from ebill; 11.SQL>insert into ebill values(‘e10’,’Yuv’,’16-dec-2019’,55); o/p : 1 row created 12.SQL>desc ebill; METE C_NAM BILL_DATE UNIT BILL_A DUE_DATE 2. Create a student database and compute the result R_NO E S MT 1. SQL>create table student(rollno number(3),name e1 Karth 17-dec-2019 45 252.5 1-jan-2020 varchar(20),sub1 number(3),sub2 number(3) ,sub3 e2 Renu 8-dec-2019 46 257 23-dec-2019 number(3),sub4 number(3) ,sub5 number(3),sub6 number(3)); e3 Annu 9-dec-2019 47 261.5 24-dec-2019 o/p : Table created e4 Adit 10-dec-2019 48 266 25-dec-2019 2. SQL> insert into student values(1,’deepak’,45,66,75,87,78,98); e5 Nithu 11-dec-2019 49 270.5 26-dec-2019 o/p : 1 row created e6 Ash 12-dec-2019 51 215 27-dec-2019 3. SQL> insert into student values(2,’vani’,30,66,75,12,78,98); e7 Ravi 13-dec-2019 52 209.5 28-dec-2019 o/p : 1 row created 4. SQL> insert into student e8 Mithu 14-dec-2019 53 204 29-dec-2019 values(3,’raju’,45,66,75,87,78,98); e9 Megha 15-dec-2019 54 198.5 30-dec-2019 o/p : 1 row created 5. SQL> insert into student e10 Yuv 16-dec-2019 55 193 31-dec-2019 values(4,’rakshit’,45,66,75,87,78,98); o/p : 1 row created 6. SQL> insert into student values(5,’karthik’,26,66,75,87,78,33); o/p : 1 row created 7. SQL> desc student; RO NAM SU SU SU SU SU SU TOT PERC RESUL LL E B1 B2 B3 B4 B5 B6 AL ENTA T NO GE 1 deep 45 66 75 87 78 98 449 74.83 pass ak 2 vani 30 66 75 12 78 98 359 59.83 fail 3 raju 45 66 75 87 78 98 449 74.83 pass 8. SQL>alter table student add(total number(3),percentage 4 raks 45 66 75 87 78 98 449 74.83 pass number(6,2),result varchar(10)); hit o/p : Table altered 5 karth 26 66 75 87 78 33 365 60.83 fail 9. SQL>update student set ik total=sub1+sub2+sub3+sub4+sub5+sub6 where rollno>0; 14.SQL>select * from student where result=’pass’; o/p : 5 rows updated 10.SQL>update student set percentage=total/6 where RO NAM SU SU SU SU SU SU TOT PERC RESUL LL E B1 B2 B3 B4 B5 B6 AL ENTA T rollno>0; NO GE o/p : 5 rows updated 1 deep 45 66 75 87 78 98 449 74.83 pass 11.SQL>update student set result=’pass’ where(sub1>=35 ak and sub2>=35 and sub3>=35 and sub4>=35 and 3 raju 45 66 75 87 78 98 449 74.83 pass sub5>=35 and sub6>=35); 4 raks 45 66 75 87 78 98 449 74.83 pass o/p : 3 rows updated hit 12.SQL>update student set result=’fail’ where(sub1<35 or sub2<35 or sub3<35 or sub4<35 or sub5<35 or sub6<35); o/p : 2 rows updated 15.SQL>select *from student where result=’fail’; 13.select * from student; RO NAM SU SU SU SU SU SU TOT PERC RES 19.SQL>select * from student order by rollno; LL E B1 B2 B3 B4 B5 B6 AL ENTA ULT RO NAM SU SU SU SU SU SU TOT PERC RESUL NO GE LL E B1 B2 B3 B4 B5 B6 AL ENTA T 2 vani 30 66 75 12 78 98 359 59.83 fail NO GE 5 karth 26 66 75 87 78 33 365 60.83 fail 1 deep 45 66 75 87 78 98 449 74.83 pass ik ak 2 vani 30 66 75 12 78 98 359 59.83 fail 16.SQL>select count(*) from student where result=’pass’; 3 raju 45 66 75 87 78 98 449 74.83 pass 4 raks 45 66 75 87 78 98 449 74.83 pass hit 5 karth 26 66 75 87 78 33 365 60.83 fail 17.SQL> select count(*) from student where result=’fail’; ik
18.SQL>select * from student where percentage>60;
RO NAM SU SU SU SU SU SU TOT PERC RESUL LL E B1 B2 B3 B4 B5 B6 AL ENTA T NO GE 1 deep 45 66 75 87 78 98 449 74.83 pass ak 3 raju 45 66 75 87 78 98 449 74.83 pass 4 raks 45 66 75 87 78 98 449 74.83 pass hit 5 karth 26 66 75 87 78 33 365 60.83 fail ik 3. Generate the employee details and compute the salary based o/p : 1 row created on the department 10.SQL> insert into employee values (1569, 01, 'Sushmitha', 6500); 1. SQL> create table employee(empid number(4),deptid o/p : 1 row created number(2),empname varchar2(25),empsal number(5)); 11.SQL> insert into employee values (1570, 02, 'Gautham', o/p : Table created 3200); 2. SQL> create table department(deptid number(2),deptname o/p : 1 row created varchar2(20),supervisor varchar2(20)); 12.SQL> insert into employee values ( 1565, 01, 'Archana', o/p : Table created 36000); 3. SQL> insert into employee values (1561, 01, 'Somesh', o/p : 1 row created 12000); 13.SQL>select * from employee; o/p : 1 row created 4. SQL> insert into employee values ( 1562, 02, 'Hemanth', 2500); o/p : 1 row created 5. SQL> insert into employee values(1563,03,'Adnan',21000); o/p : 1 row created 6. SQL> insert into employee values(1564,02,'Pooja',28000); o/p : 1 row created 14.SQL> insert into department values (01, 'purchase', 7. SQL> insert into employee values(1566,02,'Pankaj',14000); 'Karthik'); o/p : 1 row created o/p : 1 row created 8. SQL> insert into employee values(1567,03,'Nikhil',42000); 15.SQL> insert into department values(02,'accounts','Ravi'); o/p : 1 row created o/p : 1 row created 9. SQL> insert into employee values(1568,03,'Disha',9000); 16.SQL> insert into department values(03,'sales','Anu'); o/p : 1 row created 17.SQL> insert into department values (04, 'apprentice', 'Mithra'); o/p : 1 row created 22.SQL> select max(empsal)from employee where deptid = 18.SQL>select * from department; (select deptid from department where deptname = 'accounts');
23.SQL> select avg(empsal)from employee where deptid =
19.SQl> select * from employee where deptid=(select deptid (select deptid from department where deptname = from department where deptname='accounts'); 'accounts');
24.SQL> select * from employee where deptid=(select deptid
from department where supervisor='Karthik'); 20.SQl> select count(*) from employee where deptid=(select deptid from department where deptname='accounts');
25.SQL> select deptname from department count where
21.SQL> select min(empsal)from employee where deptid = deptid in(select deptid from employee group by deptid (select deptid from department where deptname = having count(*)=1); 'accounts'); o/p : no rows selected 26.SQL> update employee set empsal=empsal+empsal*0.15 where deptid=(select deptid from department where deptname = 'sales'); o/p : 3 rows updated 27.SQL> alter table employee add bonus number(5); o/p : Table Altered 28. SQL> update employee set bonus=empsal*0.05; o/p : 10 rows updated 29.SQL> select * from employee;
30.SQL> delete from employee where deptid=(select deptid
from department where deptname='apprentice'); o/p : 0 rows selected 31. SQL> select * from employee; 4. Create database for the Bank transaction o/p : 1 row created 7. SQL> insert into customer values(113, 'Gopal', 1. SQL> create table customer(cno number(4) primary 'BANGALORE', '9908776655'); key,cname varchar2(25),caddress varchar2(50), cphone o/p : 1 row created char(12)); 8. SQL> insert into customer values(114, 'David', o/p : Table created 'BANGALORE', '9988776155'); 2. SQL> desc customer; o/p : 1 row created 9. SQL> insert into customer values(115, 'Mohammed', 'BANGALORE', '9188776655'); o/p : 1 row created 10.SQL> insert into bank values(111, 5000, '28-Jan-2014', 'D', 3. SQL> create table bank(accno number(8) not 11); NULL,tramount number(8,2) check (tramount>0),trdate o/p : 1 row created date,trtype char,cno number(4)); 11.SQL> insert into bank values(112, 1500, '20-April-2014', o/p : Table created 'D', 11); 4. SQL> desc bank; o/p : 1 row created 12.SQL> insert into bank values(113, 52500, '24 - September - 2014', 'D', 11); o/p : 1 row created 13.SQL> insert into bank values(114, 17000, '01 - October - 2014', 'D', 11); 5. SQL> insert into customer values(111, 'Ayush', o/p : 1 row created 'BANGALORE', '9988776655'); 14.SQL> insert into bank values(115, 64275, '18-May-2014', o/p : 1 row created 'D', 11); 6. SQL> insert into customer values(112, 'Yashaswini', o/p : 1 row created 'BANGALORE', '9988736655'); 15.SQL> select * from customer; CNO CNAME CADDRESS CPHONE 111 Ayush BANGALORE 9988776655 20.SQL> select *from customer order by cname desc; 112 Yashaswini BANGALORE 9988736655 CNO CNAME CADDRESS CPHONE 113 Gopal BANGALORE 9908776655 112 Yashaswini BANGALORE 9988736655 114 David BANGALORE 988776155 115 Mohammed BANGALORE 9188776655 115 Mohammed BANGALORE 9188776655 113 Gopal BANGALORE 9908776655 16.SQL> select * from bank; 114 David BANGALORE 9988776155 111 Ayush BANGALORE 9988776655 21.SQL> update bank set tramount=2400 where accno =113; o/p : 1 row updated 22.SQL> alter table customer modify caddress char(50); o/p : Table Altered 17.SQL> select * from bank where trdate>='01-mar-2014'; 23.SQL> delete from bank where accno=1300; o/p : 0 rows deleted 24.SQL> create table custem as (select * from customer where cno between 113 and 115); o/p : Table created 25.SQL> select * from custem; 18.SQL> select accno,customer.cno,cname from CNO CNAME CADDRESS CPHONE customer,bank where customer.cno=bank.cno; 113 Gopal BANGALORE 9908776655 o/p : no rows selected 19.SQL> select trtype, count(*)from bank group by trtype; 114 David BANGALORE 988776155 115 Mohammed BANGALORE 9188776655
26.SQL> select * from customer where cname like 'G%';
32.SQL> select accno,count(*) from bank group by accno CNO CNAME CADDRESS CPHONE having count(*)>1; 113 Gopal BANGALORE 9908776655 o/p : no rows selected 33.SQL> select * from customer where cphone='NULL'; 27.SQL> select sysdate from dual; o/p : no rows selected 34.SQL> delete from customer; o/p : 5 rows deleted 35.SQL> drop table bank; 28.SQL> select sum(tramount) from bank; o/p : Table dropped 36.SQL> drop table customer; o/p : Table dropped 29.SQL> create view viewcust as select cno,cphone from customer; o/p : View created 30.SQL> select * from viewcust;