DAY-1
//Cdac DATABASE//
1.
/*SELECT *
from course
2.
from course
3.
/*SELECT rollNo,concat(name, ' ', 'has completed his ', ' ', degree,' ','in year'),year,sex,deptNo,advisor
FROM student
WHERE rollNo>=1;*/
4.
FROM professor
5.
/*SELECT startYear
FROM professor
6.
/*SELECT startYear
FROM professor
WHERE startYear>='2017-01-01'
AND startYear<='2017-12-31';*/
7.
/*SELECT cname
FROM course
WHERE credits='d'
8.
/*SELECT cname
FROM course
WHERE credits='b'
and deptNo>1;*/
9.
/*SELECT cname
FROM course
WHERE credits='b'
and deptNo=5;*/
10.
/*CREATE VIEW [UNIQUE name] AS //SELECT DISTINCT name ,deptId,hod why not this we can write */
from department
WHERE deptId>=1;
11.
/*SELECT hod.department
from department
WHERE deptNo<4;
12.
13.
/*SELECT name
FROM student
WHERE sex='female';*/
14.
/*SELECT cname
FROM course;*/
15.
/*SELECT name,degree,year,sex,deptNo,advisor
FROM student
WHERE rollNo>=1;*/
Day-3
hiredate date,
sal decimal(10,2),
comm decimal(10,2),
losal decimal(10,2),
hisal decimal(10,2));
commit;
1. Write a query to display the last name, department number, and department name for all employees.
2. Create a unique listing of all jobs that are in department 80. Include the location of the department in
the output.
3. Write a query to display the employee last name, department name, location ID, and city of all
employees who earn a commission.
4. Display the employee last name and department name for all employees who have a (lowercase) in
their last names.
5. Write a query to display the last name, job, department number, and department name for all
employees who work in Toronto.
6. Display the employee last name and employee number along with their manager’s last name and
manager number. Label the columns Employee, Emp#, Manager, and Mgr#, respectively.
7. display all employees including King, who has no manager. Order the results by the employee
number.
8. Create a query that displays employee last names, department numbers, and all the employees who
work in the same department as a given employee. Give each column an appropriate label.
9. Show the structure of the JOB_GRADES table. Create a query that displays the name, job,
10. Create a query to display the name and hire date of any employee hired after employee Davies.
11. Display the names and hire dates for all employees who were hired before their managers,
along with their manager’s names and hire dates. Label the columns Employee, Emp
Solution:Assingment Answers
1.
or
or
2.
3.
or
or
select e.ename,d.dname from employee,dept where e.deptno=d.deptno AND ename LIKE %A%;
5.
6.
or
or
7.
8.
or
or
select e.ename,e.deptno,c.ename,c.deptno
9.
or
select e.name,d.name,e.job,e.sal,s.grade
or
or
10.
FROM employee e
ON e.empno=SMITH.empno
or
SELECT e.ename, e.hiredate
or
select e.ename,e.hiredate
where x.ename='FORD'
and x.hiredate<e.hiredate;
11.
FROM employee e
ON (MANAGER.empno = '7566')
5.display the manager id & salary of the lower-paid employee that manager.Exclude where mgrno is not
known.
from employee
group by mgr
having min(sal)<6000
Ques1:Display the name of employee who are getting the salary more than x.
Ans: select ename,job,sal from employee where sal>(select sal from employee where ename='BLAKE');
Ques2: Display the emp list who work in the same dept of x.
ANS2:select ename,job,sal from employee where deptno=(select deptno from employee where
ename='BLAKE');
or
select ename,job,sal from employee where deptno=(select deptno from employee where
ename='BLAKE');
or
select ename,job,sal
from employee
ques3:Display the emp name & job who work are same job of x.
from employee
or
select ename,job,sal
from employee
AND ename<>'BLAKE';
Ques4:Print the details of emp who’s job id is like empid x and salary is greater than equal to salary of
emp id y.
from employee
or
select ename,job,sal
from employee
or
select ename,job,sal
from employee
from employee ;
or
select ename,sal
from employee
from employee)
Ques6:select the name of emp which getting max salary.
from employee ;
or
select ename,sal
from employee
from employee)
Ques7: select the name of emp which getting 2nd max salary.
Ans8. select sal from (select sal from employee) employee LIMIT 5;
or
select sal from (select sal from employee) employee ORDER BY sal LIMIT 5;
Ques9:Display all dept that have min salary greater than the min salary of dept 30.
Ans:9.
select min(sal),deptno
from employee
group by deptno
Ans:10.
from employee
group by job) e;
Ques11:Display the name of the employees who earn same salary as the min salary of each dept.
Ques12:Display employee who are not programmer and who’ salary is less than any of the IT prog.
Ques15:Display the detail of the employee who are manager and work in the same department as the
employee with empno=7499 and empno=7521.
Day-6
Assignment on PL/SQL
Ques2: Write PL/SQL block to display the employee details according to their deptno. Will be a user choice.
Ques3: Write a PL/SQL procedure to display the details of the employee who’s salary is greater than amount
entered by user.
Ques4: Write PL/SQL procedure to display high salary of a particular dept of user choice.
Ques5: Write a PL/SQL procedure to display no. of records or rows entered by the user.
Ques6: Write a PL/SQL procedure to display the no. of employee in a particular job category.
Solution:
/*delimiter $$
begin
set c=a+b;
end $$
*/
call print4(23,34,@c);
select @c;
/*delimiter $$
begin
select max(sal)
end $$
*/
call getdata(10);
/*delimiter $$
begin
end $$
*/
call getdata3(20,@top)
select @top;
1.
/*delimiter $$
end$$
*/
call display();
2.
/*delimiter $$
begin
select *
end $$
*/
call display1(20);
3.
/*delimiter $$
begin
select *
end $$
*/
call display2(2000);
4.
/*delimiter $$
begin
end $$
*/
5.
/*delimiter $$
begin
select max(sal)
end $$
*/
call display3a(20);
6.
/*delimiter $$
begin
select *
from employee LIMIT l1;
end $$
*/
call display4(5);
7.
/*delimiter $$
begin
select count(ename)
end $$
*/
call display5();
8.
/*delimiter $$
begin
select count(ename)
end $$
*/
call display7('MANAGER');
Day-7
/*delimiter $$
begin
select a;
if mod(a,2) then
else
end if;
end $$
*/
call Q1(24);
/*delimiter $$
begin
select a;
if mod(a,2)=0 then
select "no. is even";
else
end if;
end $$
*/
/*delimiter $$
begin
select b;
then
else
end if;
end $$
*/
Q3: create a procedure to display or find the seniority of the two employee according to their date of
joining.
/*delimiter $$
declare h1 date;
declare h2 date;
where empno=e1;
where empno=e2;
if h1>h2 then
else
end if;
end $$
*/
Q4: Write PL/SQL procedure that will accept the emp no. and find the salary of that person. If the
salary of that person is less than 1000 then hike 30% ,if the salary is b/w 1001-2000 give him 20% hike
& give 10% if other.
/*delimiter $$
begin
if sal1<1000
then
update employee set sal=sal1+sal1*0.10 where empno=eno;
then
else
end if;
end $$
*/
/*delimiter $$
begin
case sal1
else
end case;
end $$
*/
Q6:Write PL/SQL block to find the grade of a particular employee if the grade is 1 or A then print
Excellent. 2->very good etc.
/*delimiter $$
begin
declare g int(4);
select hisal1;
if(g=1)
then
select "Excellent";
elseif(g=2)
then
select "Good";
else
select "Average";
end if;
end $$
*/
DAY-8 PL/SQL Function And Procedure
/*delimiter $$
begin
declare x int(5);
set x=1;
Repeat
select x;
set x=x+1;
until x>10
end Repeat;
end $$
*/
/*delimiter $$
begin
declare x int(5);
set x=1;
while x<5
do
select x;
set x=x+1;
end while;
end $$
*/
/*delimiter $$
begin
declare x int(5);
set x=1;
while (x<=y)
do
select x;
set x=x+1;
end while;
end $$
*/
begin
declare fact int(100);
set fact=1;
set i=1;
while i<=3 do
select fact;
select i;
set fact=fact*i;
set i=i+1;
end while;
select fact;
end $$
*/
/*delimiter //
returns int(10)
DETERMINISTIC
begin
set i=1;
while i<=7 do
return fact;
return i;
set fact=fact*i;
set i=i+1;
end while;
return fact;
end //
*/
call Test6(6);
*/
/*
delimiter //
returns int
DETERMINISTIC
begin
declare x int(10);
set str='';
set x=1;
xyz:loop
if x<=10 then
set x=x+1;
iterate xyz;
else
leave xyz;
end if;
end loop;
return str;
end //
*/
/*delimiter //
create function f3b()
returns varchar(20)
DETERMINISTIC
begin
declare x int(10);
set str='';
set x=1;
xyz:loop
if x<=10 then
iterate xyz;
else
leave xyz;
end if;
end loop;
return str;
end //
*/
/*delimiter //
returns varchar(20)
DETERMINISTIC
begin
declare x int(5);
set str='';
set str2='';
set str1='A';
set x=1;
xyz:loop
if x<=10 then
set x=x+1;
iterate xyz;
else
leave xyz;
end if;
end loop;
return str2;
end //
*/
select f3e();