0% found this document useful (0 votes)
2 views

assignment 1 6638 SQL

The document contains a series of SQL query questions related to employee data management, including tasks such as retrieving unique job codes, listing employee details, filtering by department, and calculating salary statistics. It also includes PL/SQL programming exercises for checking even numbers, printing series, and displaying employee information based on ID. Each question is followed by an output section, indicating the expected results for the queries.

Uploaded by

Arshdeep Kaur
Copyright
© © All Rights Reserved
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
0% found this document useful (0 votes)
2 views

assignment 1 6638 SQL

The document contains a series of SQL query questions related to employee data management, including tasks such as retrieving unique job codes, listing employee details, filtering by department, and calculating salary statistics. It also includes PL/SQL programming exercises for checking even numbers, printing series, and displaying employee information based on ID. Each question is followed by an output section, indicating the expected results for the queries.

Uploaded by

Arshdeep Kaur
Copyright
© © All Rights Reserved
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/ 68

PRACTICAL FILE

Ques1. Create a query to display unique job codes from the EMPLOYEES table.
OUTPUT:

1
Ques2. List all information about all employees.
OUTPUT:

2
Ques3. List all the employee names along with their salary.
OUTPUT:

3
Ques4. List all the employee’s names whose department number is 50.

OUTPUT:

4
Ques5. List the names of employees where job is Manager or Clerk.

OUTPUT:

5
Ques6. List the details of the employees who have joined before the end of September
1995.

OUTPUT:

6
Ques7. List the names of employees who are not 'Clerk'.

OUTPUT:

7
Ques8. List the names of the employees whose employee numbers are 101,116,120, 130.

OUTPUT:

Ques 9. List the employee details not belonging to the department 10, 30, 40.
OUTPUT;

8
Ques10. List the employee names and salary, whose salary is greater than 6000 and less
than 10000.
OUTPUT:

9
Ques11. List the employee’s names, who have joined before 30 June 94 and after
December 94.
OUTPUT:

10
Ques12. List commission and employee names, which are availing the commission.
OUTPUT:

11
Ques13. List the name of the employees and designation (job) of the employee who does
not report to anybody (i.e. Manager is NULL).
OUTPUT:

Ques14. List the details of employees whose salary is greater than 2000 and commission
is Null.

OUTPUT:

12
Ques15.List the employee names whose names start with "S" and “D”.
OUTPUT:

13
Ques16. List the employee names and job ids having "i" as the second character in their
first name.
OUTPUT:

14
Ques17. Create a query to display Employee ID, Name, Job and hire date after
renaming the column headings to Employee #, Employee, Job, and Hire Date.
OUTPUT:

15
Ques18. Create a query that displays the employees’ last names and commission
amounts calculated on their salaries.
OUTPUT:

16
Ques19. Create a query that displays the first eight characters of the employees’ last
names and their salaries. Sort the data in descending order of salary. Label the column
EMPLOYEES_AND_THEIR_SALARIES.

OUTPUT:

17
Ques20. Create a query to display all the data from the EMPLOYEES table. Separate
each column by a comma. Name the column THE_OUTPUT.

OUTPUT:

18
Ques21. Create a query to display the last name and salary of employees earning more
than $12,000.

OUTPUT:

Ques22. Display details of employee with ID 150 or 160.

OUTPUT:

19
Ques23. Display details of the employees where commission percentage is null and
salary in the range 3000 to 7000 and department is 50.

OUTPUT:

Ques24. Display employees where the first name or last name starts with S or T.

OUTPUT:

20
Ques25. Display employees who joined after 1st January 1998.

OUTPUT:

21
Ques26. Display employees who joined in the year 1999.

OUTPUT:

22
Ques27. Select all the data of employees that work in department 50.

OUTPUT:

23
Ques28. Select all the data of employees that work in department 60, 20 or department
80.

OUTPUT:

24
Ques29. Select all the data of employees whose last name is "Smith".

OUTPUT:

Ques30. Select all the data of employees whose last name is "Smith" or "Taylor".

OUTPUT:

25
Ques31. Select the last name of all employees, without duplicates.

OUTPUT:

26
Ques32. Display first name and last name after converting the first letter of each name
to upper case and the rest to lower case.

OUTPUT:

27
Ques33. Display first name in upper case and email address in lower case for employees.

OUTPUT:

28
Ques34. Display first name of employees who joined in 1995.

OUTPUT:

Ques35. Display first name, salary, commission pct, and hire date for employees with
salary less than 10000.

OUTPUT:

29
Ques36. Write a Query to display the last name and salary for all employees whose
salary is not in the range of $5,000 and $12,000.

OUTPUT:

30
Ques37. Write a Query to display the last name, salary, and commission for all
employees whose commission amount is 20%.

OUTPUT:

Ques38. Display last name, job title of employees who have commission percentage and
belongs to department 30.

OUTPUT:

31
Ques39. Display number of employees joined after 15th of the month.

OUTPUT:

32
Ques40. Display the first name and join date of the employees who joined between 1998
and 2000.

OUTPUT:

33
Ques41. Display the last name and department number of all employees in departments
20 and 50 in alphabetical order by name.

OUTPUT:

34
Ques42. Display the last name and hire date of every employee who was hired in 1994.

OUTPUT:

Ques43. Display the last name and job title of all employees who do not have a manager.

OUTPUT:

35
Ques44. Display the last name concatenated with the job ID, separated by a comma and
space, and name the column Employee and Title.
OUTPUT:

36
Ques45. Display the last name of all employees who have an a and an e in their last
name.

OUTPUT:

37
Ques46. Display the last name, salary, and commission for all employees who earn
commissions. Sort data in descending order of salary and commissions.

OUTPUT:

38
Ques47. Display the last names of all employees where the third letter of the name is an
a.

OUTPUT:

Ques48. For each employee, display the employee number, last_name, salary, salary
increased by 15% and add a column that subtracts the old salary from the new salary.
Label the columns New Salary and Increase.

OUTPUT:

39
Ques49. Write a Query to list the last name and salary of employees who earn between
$5,000 and $12,000, and are in department 20 or 50. Label the columns Employee and
Monthly Salary, respectively.

OUTPUT:

40
Ques50. Demonstrate the use of all the character, date and number functions in Oracle.
OUTPUT:
CHARACTER FUNCTIONS:
LOWER:

UPPER:

INITCAP:

CONCAT:

SUBSTRING:

41
Length:

INSTR:

LPAD:

RPAD:

TRIM:

NUMBER FUNCTIONS:
ROUND:

42
TRUNCATION or TRUNC:

MOD function:

43
DATES FUNCTION:
MONTH_BETWEEN:

ADD_MONTHS:

NEXT_DAY:

LAST_DAY:

ROUND:

TRUNCATE OR TRUNC DATE:

44
Ques51. Display average, maximum and minimum salary department wise.
OUTPUT:

Ques52. Display job ID, number of employees, sum of salary, and difference between
highest salary and lowest salary of the employees of the job.
OUTPUT:

45
Ques53. Display job title and average salary of employees job title wise.

OUTPUT:

46
Ques54.Display manager ID and number of employees managed by the manager.
OUTPUT:

47
Ques55. Display department ID and number of employees and sum of salaries of
employees who earn more than 8000.

OUTPUT:

Ques56. Display average salary of employees in each department who have commission
percentage (where commission_pct is null order by department id).
OUTPUT:

48
Ques57. Display job ID for jobs with average salary more than 10000(Having Clause).
OUTPUT:

Ques58. Display departments where any manager is managing more than 5 employees.
OUTPUT:

49
Ques59. Display details of departments in which the maximum salary is more than
10000 (Having Clause).
OUTPUT:

Ques60. Display department id, employee count, and the difference between maximum
salary for the job and salary of the employee.
OUTPUT:

50
Ques61. List the id of all departments who have more than 3 employees.
OUTPUT:

Ques62. Display job Title, the difference between minimum and maximum salaries for
jobs with max salary in the range 10000 to 20000.
OUTPUT:

51
Ques63. Display the number of employees joined year-wise and their average salaries.
OUTPUT:

Ques64. Retrieve department wise total number of employees in the company.


OUTPUT:

52
Ques65.Write a query to display the number of people joined in the same month.
OUTPUT:

Ques66. Write a query that displays the difference between the highest and lowest
salaries. Label the column DIFFERENCE.
OUTPUT:

53
Ques 67. Create a query to display the job, the total salary for that job, for departments
20, 50, 80, and 90, giving each column an appropriate heading.
OUTPUT:

Ques68. Display departments in which more than five employees have commission
percentage.
OUTPUT:

54
QUES69. Create a view that display the emp id, names, hiredate and salary of all the
employees hired after '01.01'1997'
OUTPUT:

QUES70. Create a view of all employee working in cities starting with S.


OUTPUT:

55
Ques71. Create a view of all employee along with the city of their location having names
between A and M.
OUTPUT:

Ques72. Create a view of employees who have a job history.

OUTPUT:

56
Ques73. Create a view that shows the employees in department 60, 70 and 90 and their
annual salary.
OUTPUT:

Ques74. Create a view on the BILLS table that looks identical to the table but has a
different name.

OUTPUT:

57
QUES 75. Create a view to display debt data of account_id 4.

Ques76. Create a view to display the NAME and STATE fields from the COMPANY
table.

58
Ques77. Create view from BILLS and BANK_ACCOUNTS table to retrieve
information
on payments where acct balance >500.

59
Ques78. Create a view that shows all states to which the bills are being sent. Also display
the total amount of money and the total number of bills being sent to each state.

Ques79. Write a query to display the last name, job, department number, and
department
name for all employees who work in Toronto.

60
Ques80. Display employee ID and the date on which the employees ended their previous
jobs.
OUTPUT:

Ques81. Display the last name, job, and salary for all employees whose job is sales
representative or stock clerk and whose salary is not equal to $2,500, $3,500, or
$7,000.
Output:

61
Ques82. Display job title, department name, employee last name, starting date for all
jobs
from 2000 to 2005.
Output:

62
Ques83. Display first name and join date of the employees who is either IT Programmer
or
Sales Man.
Output:

Ques84. Display the details of departments in which the max salary is greater than
10000
for employees who did a job in the past.
Output:

63
Ques85. Write a query to display each department’s name, location, number of
employees,
and the average salary for all employees in that department. Label the columns
Name, Location, Number of People, and Salary, respectively. Round the average
salary to two decimal places.
Output:

64
Ques86. Display the last name and salary of every employee who reports to King.
OUTPUT:

65
Ques87. Write a PL/SQL program to check whether a given number is even or not.
Even: -
declare
inVal number:=10;
begin
if(mod(inval, 2)=0) then
dbms_output.put_line('Even Number');
else
dbms_output.put_line('Odd Number');
end if;
end;

ODD: -
declare
inVal number:=101;
begin
if(mod(inval, 2)=0) then
dbms_output.put_line('Even Number');
else
dbms_output.put_line('Odd Number');
end if;
end;

66
Ques88. Write a program in PL/SQL to print the series of numbers starting from the
numbers n till 1.
declare
n number:=&n;
begin
for i in 0..n-1 loop
dbms_output.put_line('the number'||(n-i));
end loop;
end;

67
Ques89. Write a program in PL/SQL to print the table of a number.
declare
NUM NUMBER:=2;
counter number:=1;
begin
while counter <= 10 loop
dbms_output.put_line(Num||' * '||counter||' = '||counter*num);
counter := counter + 1;
end loop;
end;

Ques90. Write a program in PL/SQL to display the salary and job name of the
employee
with a given employee ID.
declare
e_sal employees.salary %type;
e_job employees.job_id %type;
begin
select salary,job_id into e_sal ,e_job from employees where employee_id=&amp;empid;
dbms_output.put_line(&#39;emp_job-----&#39;||e_job);
dbms_output.put_line(&#39;emp_sal-----&#39;||e_sal);

68

You might also like