Lab 1
Lab 1
Lab1: Introduction
Basic Select Statement
Ruba Sultan
DEFINITIONS
3
SQL STATEMENTS
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.
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.
9
PROCEDURES TO USE SAMPLE TABLES
3-Enable both
CONNECT and
RESOURCE roles
10
4-Check all Directly
Granted System
Privileges
DEMONSTRATION TABLES
COUNTRIES
DEPARTMENTS
EMPLOYEES
JOBS
JOB_HISTORY
LOCATIONS
11
DATA RETRIEVAL
Join
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
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
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 ||
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
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
DESC[RIBE] tablename
Question11
Display table structure for EMPLOYEES and
DEPTARTMENTS tables.
20
ASSIGNMENT 1
21
SELECTION
22
9 Introduction to Oracle: SQL and PL/SQL P2-4Neena Kochhar, Ellen Gravina and Priya Nathan, July 1999
CHARACTER STRING AND DATES
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)
26
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
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
commission.
SORTING
Sorting rows can be implemented using
ORDER BY clause
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