0% found this document useful (0 votes)
56 views33 pages

Lab 1

Here are the key points about using the LIKE operator: - The LIKE operator is used to search for a pattern in a column value - It supports two wildcard characters: - % - Matches zero or more characters - _ - Matches a single character - The pattern is enclosed in single quotes - The column value being searched is not enclosed in quotes Some examples: - lastname LIKE 'Sm%' finds all names starting with Sm - lastname LIKE '%son' finds all names ending with son - lastname LIKE '_m_' finds all 4 letter names with m in the middle So the LIKE operator allows flexible pattern matching rather than exact equality.

Uploaded by

Yazan Abu khaled
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)
56 views33 pages

Lab 1

Here are the key points about using the LIKE operator: - The LIKE operator is used to search for a pattern in a column value - It supports two wildcard characters: - % - Matches zero or more characters - _ - Matches a single character - The pattern is enclosed in single quotes - The column value being searched is not enclosed in quotes Some examples: - lastname LIKE 'Sm%' finds all names starting with Sm - lastname LIKE '%son' finds all names ending with son - lastname LIKE '_m_' finds all 4 letter names with m in the middle So the LIKE operator allows flexible pattern matching rather than exact equality.

Uploaded by

Yazan Abu khaled
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/ 33

DATABASE LAB

Lab1: Introduction
Basic Select Statement

Ruba Sultan
DEFINITIONS

 Database:is an organized collection of


information.

 Database Management System (DBMS):


is a program that stores, retrieves and
modifies data in database.

 StructuredQuery Language (SQL): is a


language used to access and modify data
in database. 2
DBMS

 DBMS that will be used Oracle 10g Express


Edition

 SQL *Plus is an SQL editor used to write SQL


statements and it’s included in Oracle
Database package.

3
SQL STATEMENTS

Data Retrieval SELECT


Data Manipulation Language (DML) INSERT
UPDATE
DELETE
Data Definition Language (DDL) CREATE
ALTER
DROP
TRUNCATE
RENAME
Data Control Language (DCL) GRANT
REVOKE
Transaction COMMIT
ROLLBACK 4

SAVEPOINT
PROCEDURES TO USE SAMPLE TABLES
Logging in as the Database Administrator2
 The first thing you need to do is to log in as the Oracle
Database XE Administrator.
 Follow these steps:
 Open the Database Home Page login window:
 On Windows, from the Start menu, select Programs (or All
Programs), then Oracle Database 10g Express Edition, and then
Go To Database Home Page2.
 At the Database Home Page login window, enter the following

information2:
 Username: Enter system for the user name.

 Password: Enter the password that was specified when Oracle


Database XE was installed. 5
PROCEDURES TO USE SAMPLE TABLES

6
PROCEDURES TO USE SAMPLE TABLES
Unlocking the Sample User Account2
 To unlock the sample user account:
 Make sure you are still logged on as the database
administrator.
 Click the Administration icon, and then click
Database Users2.
 Click the HR schema icon to display the user
information for HR.

7
8
PROCEDURES TO USE SAMPLE TABLES
 Under Manage Database User, enter the
following settings2:
 Password and Confirm Password.
 Account Status: Select Unlocked.
 Roles: Ensure that both CONNECT and
RESOURCE are enabled.
 Directly Granted System Privileges: Check them all.

 Click Alter User.

9
PROCEDURES TO USE SAMPLE TABLES

5-Click on Alter User

1-Set a password for HR


schema

2-Set a Account Status to


Unlocked

3-Enable both
CONNECT and
RESOURCE roles
10
4-Check all Directly
Granted System
Privileges
DEMONSTRATION TABLES

 There are different tables that will used in this lab:

 COUNTRIES

 DEPARTMENTS

 EMPLOYEES

 JOBS

 JOB_HISTORY

 LOCATIONS

11
DATA RETRIEVAL

 SELECT statement capabilities3:


 Selection
 Projection

 Join

 Basic SELECT Statement4


SELECT [DISTINCT] {*,column [alias],…}
FROM tablename;

12
3 Introduction to Oracle: SQL and PL/SQL P1-3 Neena Kochhar, Ellen Gravina and Priya Nathan, July 1999
4 Introduction to Oracle: SQL and PL/SQL P1-4 Neena Kochhar, Ellen Gravina and Priya Nathan, July 1999
QUESTIONS

 Question1
Write a query to display all employee’s
information.
 Question2
Write a query to display all department’s
information.
 Question3
Write a query to display all department’s
names and their location.
 Question4
Write a query to display all information in
JOB_HISTORY table. 13
ARITHMETIC OPERATORS
Operato Description Operat Precedenc
r or e
+ Addition () High
- Subtraction
/ *
* Multiplicati
on + - Low
/ Division
 Arithmetic operations can be used with both
NUMBER and DATE data types. 14
QUESTIONS

 Question5
Write a query to display all employee’s names
and their salaries and their annual salaries.

 Question6
Modify the previous query where each
employee gets $100 bonus for each month.

 Question7
Write a query to display all employee’s
numbers, names and their annual income.
15
NULL VALUE

 Null: is a value that is unavailable,


unassigned, unknown or inapplicable, and it
is not same as zero or blank space5.

 Arithmetic expressions containing Null value


evaluated to Null6.

16
5 Introduction to Oracle: SQL and PL/SQL P1-14 Neena Kochhar, Ellen Gravina and Priya Nathan, July 1999
6 Introduction to Oracle: SQL and PL/SQL P1-15 Neena Kochhar, Ellen Gravina and Priya Nathan, July 1999
COLUMN ALIAS

 Rename column heading7.


 Immediately follows column name, use AS keyword
between column name and alias7.
 Requires double quotation if contains spaces or special
characters or case sensitive7.

 Question8
Write a query to display all employee’s numbers,
names and their annual income
Note: use appropriate column heading.

17

7 Introduction to Oracle: SQL and PL/SQL P1-16 Neena Kochhar, Ellen Gravina and Priya Nathan, July 1999
CONCATENATION OPERATOR ||

 Concatenate a columns or a character strings to


other columns the result will be in one column.
 Use two vertical bars || for concatenation.

 Question9
Write a query to display all employee’s names and
their jobs.
Note: format must be as the following example

CLARK is a MANAGER 18
DISTINCT KEYWORD

 Used to eliminate duplicate rows8


 Used after SELECT statement8.

 Question10
Write a query to display all job positions in
EMPLOYEES table.

19

8 Introduction to Oracle: SQL and PL/SQL P1-23 Neena Kochhar, Ellen Gravina and Priya Nathan, July 1999
DISPLAY TABLE STRUCTURE

 Using DESCRIBE command.

DESC[RIBE] tablename

 Question11
Display table structure for EMPLOYEES and
DEPTARTMENTS tables.

20
ASSIGNMENT 1

 List at least ten different DBMS.


 List different versions of Oracle DBMS.

 Write a query to display all data from emp table,


separate each column by comma.
Note: use appropriate column heading.

21
SELECTION

 Restricting Row using WHERE clause9

SELECT [DISTINCT] {*,column [alias],…}


FROM tablename
WHERE condition(s);9

22

9 Introduction to Oracle: SQL and PL/SQL P2-4Neena Kochhar, Ellen Gravina and Priya Nathan, July 1999
CHARACTER STRING AND DATES

 Character string and date values enclosed in single


quotation10.
 Character values are case sensitive and date values are
format sensitive10.
 Default Date format is DD-MON-YY10.

23

10 Introduction to Oracle: SQL and PL/SQL P2-6 Neena Kochhar, Ellen Gravina and Priya Nathan, July 1999
COMPARISON OPERATORS
Operator Description
= Equal to
<> or != Not Equal to
> Greater than
< Less than
>= Greater than or equal
<= Less than or equal
24
QUESTIONS

 Question12
Write a query to display all employee’s information
whose salary $2800 or more and less than or equal
$3500.

 Question13
Write a query to display all employee’s information
whose job FI_MGR.

25
MORE COMPARISON OPERATOR

Operator Meaning
BETWEEN …AND… Between two values(inclusive)

IN Match value in a list of values

LIKE Match character pattern

IS NULL Is NULL value

26

This Table form


Introduction to Oracle: SQL and PL/SQL P2-6 Neena Kochhar, Ellen Gravina and Priya Nathan, July 1999
QUESTIONS

 Question14
Write a query to display all employee’s
information whose salary $2800 or more and less
than or equal $3500.

 Question15
Write a query to display employee’s numbers,
names and salaries whose salary $800 or $3000
or $5000. 27
USING LIKE OPERATOR12

 Use the LIKE operator to perform wildcard


searches of valid search string values.
 Search conditions can contain either literal
characters or numbers.
% denotes zero to many character.
 _ denotes one character

28

12 Introduction to Oracle: SQL and PL/SQL P2-12 Neena Kochhar, Ellen Gravina and Priya Nathan, July 1999
QUESTIONS

 Question16
Write a query to display all employee’s
information for employees whose names
contain letter A.

 Question17
Write a query to display all employee’s
information for employees whose names
contain letter A and contain four letters.
29
LOGICAL OPERATOR

Operat Operato
Description Precedence
or r
NOT Returns True if
NOT High
condition is False

AND Returns True if both


AND
conditions
evaluated True
Low
OR Returns True if one of
OR
conditions
30
evaluated True
QUESTIONS
 Question18
Write a query to display names, jobs and
salaries for employees who get more than
$2650 and their job IT_PROG.
 Question19
Write a query to display names, jobs and
salaries for employees who do not get $800,
$3000 or $5000.
 Question20
Write a query to display all employee’s
information for employees who have known 31

commission.
SORTING
 Sorting rows can be implemented using
ORDER BY clause

 There are two options:


 ASC: ascending order, default13

 DESC: descending order13

 The ORDER BY clause comes last in the


SELECT statement13. 32

13 Introduction to Oracle: SQL and PL/SQL P2-22 Neena Kochhar, Ellen Gravina and Priya Nathan, July 1999
QUESTIONS
 Question21
Write a query to display all employee’s
information, sort output according to hire date
form most recently hired to least hire date.

 Question22
Write a query to display all employee’s names
and their annual income sort output according
to annual income in ascending.

33

You might also like