Professional Documents
Culture Documents
ENGINEERING FACULTY
ALMATY
2009
1
LABORATORY WORK-1 : Introduction to sqlplus
2
LABORATORY WORK-2 : Using arithmetics operators
a
3-SQL statement to calculate the area of circle. Table : CIRCLE
c
a
3
5-Write an SQL statement to list addition of salary and commission for each employee in the
table “EMP”
6-Write an SQL statement to calculate the remainder of X divided by 3 in the table MATH.
7-Write an SQL statement to calculate the remainder of Y divided by 4 in the table MATH.
8-Write an SQL statement to calculate the remainder of 21 divided by X in the table MATH.
4
LABORATORY WORK-3 : Using DATE function
4- Which day have they started to work ?(EMP) ( day as number e.g. 21)
5- Which day have they started to work ? (EMP) ( full day name e.g. SATURDAY )
5
21- Create the stuff table below.
6
LABORATORY WORK-4 : Using WHERE clause
emp
5- List employee whose salary is smaller than 1500 and department no=30
7
15- List the last letter of ENAME is “N”
16- List ENAME whose salary is not equal to 1000 and 2000
8
LABORATORY WORK-5 : Using Built-in Functions
STUDENT CLASS
Nurlan MULDASHEV 3A
Syrym NURUMBETOV 4A
3-Write an SQL statement to returns the index of the books as shown in the figure below.
4-Write two SQL statement to returns the position of the third ‘or’ in the following string.
(search from left and right)
Corporate Floor
5-Write an SQL statement to returns the position of the first “FOUR” from the string: Take
the first four characters
6-Write an SQL statement to returns the position of the second “ten” from the string : seven
ten eight nine ten one
7-Write an SQL statement to returns the position of the second “a” from the string : Take the
first four characters
9
8-Write an SQL statement to returns the value between two commas from the STRING table
below.
TABLE : string
text
---------------
Abc,def,gfh
Sd,fghjk,gh
Asdfgh,f,fghjjk
9-Write an SQL statement to returns JOBs in ascending order by its character number.
10-Write an SQL statement to returns names without any spaces from both sides.
TABLE : students
Name
----------
Nurlan
Asem
Aynura
Write an SQL statement to update ENAME column from table “EMP“ as shown below.
13-Write an SQL statement to returns the ASCII code of the third character from “ename” in
EMP.
10
LABORATORY WORK-6 : Using Built-in Functions
f )a sin(0.5) g ) cos(450 )
sin 30
h) + tan 2 45 + log 3 600 + ln 6 + 812
cos 70
11
4-Write an SQL statement which returns the full name of customer_id as shown in the figure.
6-Write an SQL statement which returns values using coalesce in order col1,col2,col3
Table: test
Col1 col2 col3
-----------------------------------
1 3
1 5
6 1
1
2 1
12
LABORATORY WORK-7 : Aggregate Functions
15-Find the name of 8th successful student from the ENT table.
16-Find the Name of Third successful student in Almaty from ENT table;
13
LABORATORY WORK-8 : Using Joins
COURSE
COURSE_ID COURSE_NAME INSTRUCTOR
CS100 INFORMATICS KOJAHMETOV
CS101 ALGORITHMS ORISBAYEV
CS213 JAVA BOGDANCHIKOV
STUDENT
STUDENT_ID STUDENT_NAME COURSE_ID GRADE
1 ASEM CS100 A
2 NURLAN CS100 A-
3 NARGIZ CS101 C
4 ALIP CS213 B
5 TOLEGEN CS100 C
6 YERNUR CS101 B
14
14-HOW CAN YOU DISPLAY THIS RESULT SET USING BIN_A TABLE ONLY.
TABLE
BIN_A
A
---
0
1
RESULT
15
LABORATORY WORK-9 : Unions and Joins
1-Write an SQL statement which returns JOB and TOTAL SALARY of jobs.
2-Write an SQL statement which returns JOB and AVERAGE SALARY of jobs.
3-Write an SQL statement which returns JOB and TOTAL SALARY of jobs is greater than
5000.
4-Write an SQL statement which returns JOB and AVERAGE SALARY of jobs is greater
than 2000.
5-Write an SQL statement which returns the average salary of all DEPTNO.
6-Display the highest,lowest,sum, and average salary of all employees.Label the columns
Maximum,Minimum,Sum,and Average, respectively. Round your results to the decimal
position.
7-Display the maximum, minimum,sum, and average salary for each job type.
8-Write a query to display the number of people with the same job.
16
9-Determine the number of managers without listing them. Label the column “Number of
Managers”
10-Write an SQL statement that will display the difference between the highest and lowest
salaries.
Label the column “Diffrenece”
11-Display the manager number and salary of the lowest paid employee for the manager.
Exclude anyone where the manager id is knot known.
Exclude any groups where the minimum salary is less than $1000. Sort the output in
Descending order of salary
12-Write a query to display the department name, location name, number of employees, and
the Average of salary for all employees in that department.
Label the columns dname,loc,Number of people, and Salary , respectively.
17
13-List DEPTNO exists in DEPT but not in EMP.
18
LABORATORY WORK-10 : Group By and Group functions
19
3 – Classes with the GPA average for each semester
20
6 – Students with average GPA=3 ?
21
8 – Semesters with GPA Average for all classes.
22
10 – Categorize people into child,teenager and adult depending on their ages
SELECT
ENAME,
DECODE( SIGN(SAL-2000 ),1,'GREATER THAN 2000', 'SMALLER THAN 2000')
SALARY
FROM EMP;
23
12 – List the number of old and new cars.
1999 2000
24
14-Retreive the full customer name of top-10 rows. 'AAL', 'American Airlines',
ILC - Intl. Leasing Corp. NOW - Northwest Orient,
SAL - Southwest Airlines SWA - Sweptwing Airlines
USAF - United States Air Force Not Known - AIRLINE
25
15-Retreive PRG_ID and Customer_Id as shown on the figure below.
16-Retreive PRG_ID and amount of each customers as shown on the figure below.
17-Retreive months and total empoyees number who started to work at that month.
26
18-List employees ,in department 10, has salary which is less than any salary of employees in
department 30
19-List all employees who are not working in department 30 and who earn more than
all employees working in department 30:
21-Retrieve the minimum and maximum salary of clerks for each department having
more than 1 clerk.
27
QUIZ
EMP
ENT
SALGRADE
DEPT
TEST
28
1- Write the result of the following SQL statement.
SELECT COALESCE(COL2,DECODE(COL3,COL1,COL1*2,COL3*3),COL1) COL
FROM TEST ;
2- Write a query which returns an employee who has the maximum salary in EMP?
(You will use EMP table)
3- Write an SQL statement which finds the third successful student(s) in ENT table. (You will
use ENT table)
5-How many different departments are there in EMP table. (You will use EMP table)
6- Write a query which finds the GRADE of TURNER. (You will use EMP table)
8-Write an SQL statement which returns all “Deptno” in emp and dept tables.
29
9- Write an SQL statement which returns the average score of ALMATY in ENT table.
10- Write an SQL statement which returns JOB and average salaries of each job,
but include only if the average salary is less than 1500. (You will use EMP table)
30
LABORATORY WORK-11 : Subqueries
1-Write a query to display the name and hire date of any employee in the same department as
SMITH. Exclude SMITH.
2-Write a query to display the employee number and name of all employees who earn more
than the average salary. Sort the result in ascending order of salary.
3-Write a query that displays the employee numbers and the names of all employees who
work in a department with any employee whose name contains a “D”
4-Display the name, and salary of every employee who reports to KING.
31
5-Display the department name, name, and job for every employee in “ACCOUNTING”
department
7-Select all employees whose salary is less than the average of all the employees' salaries in
the same department.
8-Select maximum salary,salary and difference salary between maximum and salary of all
employees.
32
9-Select maximum salary of all departments with employees.
33
LABORATORY WORK-12 : Producing Readable Output with iSQLPLus
34
LABORATORY WORK-13 : Sql commands
1-Based on the departments table below, rename the departments table to depts.
2-Based on the employees table below, add a column called salary that is a number(6)
datatype.
3-Based on the customers table below, add two columns - one column called contact_name
that is a varchar2(50) datatype and one column called last_contacted that is a date datatype.
4-Based on the employees table below, change the employee_name column to a varchar2(75)
datatype.
5-Based on the customers table below, change the customer_name column to NOT allow null
values and change the state column to a varchar2(2) datatype.
35
7-Based on the departments table below, rename the department_name column to dept_name.
CREATE TABLE departments ( department_id Number(10), department_name
Varchar2(50));
36
LABORATORY WORK-14 : Introduction to PL/SQL
3-Create a PL/SQL block that computes the commission amount for a given employee based
on
the employee's salary. Table : emp , user : scott
-If the employee's salary is less than 1000, set the commission amount for employee to 10%
of salary
-If the employee's salary is between 1000 and 1500, set the commission amount for employee
to 15%
of salary.
-If the employee's salary exceeds 1500, set the commission amount for employee to 20% of
salary
-If the employee's salary is null, set the commission amount for employee to 0.
4-Find the minimum salary from the emp table and print to screen.
5-Define an external variable , name is x, change it's value and see the current value of x.
6-Your table has the values of names only. Write a PL/SQL block to append one asterisk for
each
character on the names to the column “star”.
8-Write a PL/SQL block to prints all odd numbers between 0 and 100 .
9-Write a PL/SQL block to prints all numbers between X and Y . Use “Accept” statement to
enter X and Y from keyboard.
37
LABORATORY WORK-15 : Constraints
Integrity Rules
1.It must be allowed to insert ”Female” and “Male” into “Gender “only.
8-On the table CH : Id, Course and semester must be unique together. Each student must have
one row
for a course in a semester.
9-Insert the following rows into tables above. Find the 4 errors while inserting following
rows.
38
10-Delete the first row from “PT”. Why can not you delete it?
Rule
3.1-The default value of Taken_date is sysdate: It means, sysdate value is inserted into
Taken_date if
any date is not inserted.
3.2- Students must pay 10 Tenge per each day. Write a query which will display students with
reading
day and paid money.
39