Download - Oracle SQL- Part 1
INTRODUCTION TO ORACLE SQL
OBJECTIVES
• At the end of this module, you should be able to:
• Know what Data is and what a Database is.
• Understand Database Management Systems and
Relational Databases.
• Understand the use of SQL and Oracle SQL.
WHAT IS ORACLE?
ORACLE is a relational database management software.
DATA is a collection of facts, such as values, numbers,
words, measurements, observations or the
descriptions of things.
• A DATABASE refers to an organized mechanism for
storing, managing and retrieving data-information. A
database performs these typical functions through
the use of tables.
• If you are familiar with spreadsheets like Microsoft
Excel, you’re probably already accustomed to
storing data in tabular form. You would just move
further from spreadsheets to databases.
• A customer database for example, would contain the
customer's ID, first name, last name, and email
address, and each row would contain an individual
customer’s data.
• A DATABASE MANAGEMENT SYSTEM (DBMS) -also called a database
manager- is a program that lets one or more
computer users, create and access data in a
database. The DBMS manages user requests so that
users and other programs are free from having to
understand where the data is physically located.
• By definition, a DBMS is a software package with
computer programs that control the creation,
maintenance, and the use of databases, allowing
organizations to conveniently develop databases for
various uses. A DBMS would also allow different user
programs to concurrently access the same database.
• Database Applications are used in banks, schools,
airlines, hospitals, cooperate offices etc.
• When we make flight reservations online, we are
providing information that is entered into a
database management system. When we buy at the
supermarket and get a receipt, that sale is recorded
in a database.
• On a more personal level, our personal computer can
have its own database management system. We may
have Microsoft Excel sheets that contain mountains
of data. Any time we fill up a sheet with data and run
queries to find and analyze data in different ways,
we are accessing a database management system.
• Our phonebook is database. When we add contacts,
delete contacts and search for friends phone
numbers on our phonebook, we are simply accessing
a database.
• A RELATIONAL DATABASE MANAGEMENT SYSTEM stores up all its
information in tables but it also stores information
about the relationship between its tables. In a
relational database management system, data can be
accessed or reassembled in many different ways
without having to change the table forms.
• To communicate with a RDBMS, we need a language.
• STRUCTURED QUERY LANGUAGE which we call SQL -pronounced in
the industry as sequel- is an international standard
language for communicating with relational
databases.
• SQL can create, delete, and change data in tables. It
can also input data into tables and remove data. It is
a data handling language.
• Just like any other language, SQL has dialects and
ORACLE SQL is the dialect that communicates with
the Oracle Database. Other dialects include: MySQL,
PLSQL, Microsoft SQL etc.
REVISION QUESTIONS
1. Explain the use of data
2. What are databases and how are they used in
today’s society.
3. What do the following abbreviations stand for:
• DBMS.
• RDBMS.
• SQL.
4. Compare a Microsoft Excel spread sheet with a
Database.
INSTALLATION AND
CONFIGURATION
OBJECTIVES
At the end of this module, students should be able to:
• Install Oracle Express Edition on their personal
computer and configure it.
• Have a fair understanding of the database home
page
INSTALLATION AND CONFIGURATION
• Oracle express edition is a free small edition of the
Oracle database. It uses a browser based interface to
create tables and other database objects, to generate
reports and to build web-based applications.
RUN INSTALLATION
• Now with Oracle Express Edition already installed
on your personal computer, do the following:
• Click the start button then
• Click Oracle Express Edition 10g/11g,
• Select Go To database home page.
Fig 1.1
• We must first log in as an administrator, so when the
LOGIN window is displayed in your web browser:
• Enter USERNAME as SYSTEM
• Enter PASSWORD as the password we choose during
installation.
• Click on LOGIN.
DATABASE HOMEPAGE
• The Database homepage will open if you input the
correct password in the LOGGIN window and this
Homepage has four large icons on it.
• Administration - is used for the sole aim of
management. It manages user accounts, manages
memory, manages storage and monitors sessions.
• Object browser- is used to create tables and other
schema objects and to browse the schema objects.
• SQL - uses the SQL command line as a tool to run
SQL commands. The SQL script is used to edit and
run script files, while the query builder is used in
building SQL queries using a graphical user
interface.
• Utilities - is used to load and unload data, to
generate data definition language, object reports and
to recycle.
DATABASE LOGIN
• You are now logged in as system, so the user name
displayed at the top of the page is system. The next
thing to do is to unlock the sample user accounts
where you would have access to some tables and
other schema objects.
• Oracle Express Edition comes with a fictional human
resource department’s database and that database
has a good number of schema objects. The user
name for the human resource department is HR, and
it is locked by default, so you would have to UNLOCK it.
To do this;
• Click on the administration icon
• Click database users
• Click the HR icon
• Under the database users, enter a password of
choice and confirm the password.
• Select Unlocked in the account status
• Under Roles, you ensure that Connect and Resource
are enabled
• Click Alter User.
• Now click Logout at the upper right corner.
Click LOGIN again.
To Login as HR as our USER NAME
• Enter the chosen password.
• Click LOGIN.
COMMAND WINDOW
You would be entering all SQL statements in the SQL
enter command window, so let us zoom in on that
window.
• On the Home-Page:
• Click the SQL icon
• Select SQL Command line and then
• Click Enter Command.
• This opens the SQL Command Window and on this
window we can create, edit, view run and delete SQL
Commands.
• The SQL Window contains a Command Editor used
to enter and edit command lines, and a Display Pane.
• The AUTO COMMIT check box is checked to enable
an auto-commit of all SQL commands. The DISPLAY
drop down is used to determine the number of rows
to be displayed in the display pane.
• The SAVE button is used to save a SQL statement
giving it a file name and a description. The RUN
button is used to run or execute a SQL command.
• On the Display Pane, we can either view the result of
a SQL command, or view a list of saved SQL
commands. The History Tab would display previous
transaction and the Describe Tab is used when we
describe schema objects.
REVISION QUESTIONS
1. What are the four Icons on the Homepage?
2. What are their respective functions?
3. Where is the RUN and SAVE button located on the
Command Window?
4. What are they used for?
5. Where are SQL Commands entered?
RETRIEVING DATA USING THE SQL
SELECT STATEMENT.
OBJECTIVES
At the end of this module, students should be able to:
1. List the capabilities of the SQL select statement.
2. Execute a basic select statement.
3. Describe how Schema objects work.
A SIMPLE SELECT STATEMENT
• A basic SELECT statement is the simplest SQL statement.
It is used to query a database and it has three basic
functions. It:
• PROJECTS - chooses the column to be returned by the
query block,
• SELECTS - chooses the rows to be returned by the query
block.
• JOINS - brings together data from different tables for
display.
• The SELECT keyword is always used with the FROM
keyword.
FORMAT:
SELECT *
FROM table_name;
• When we want to display all the rows in all the
columns in a table, we simply say:
FIG 2.1
• This simple select statement will display all the data
in the employees table. However when we want to
display specific columns in the table we do so by
listing these column names in the SELECT statement
and separating each column name with a comma.
FORMAT:
SELECT column_name1, column_name2
FROM table_name;
EXAMPLE
• Notice that this query returns the employee_id,
first_name and the last_name column for all the rows
in the employees table.
COLUMN ALIASES
• When columns are displayed in the display pane by a
SELECT statement, you would notice that the name of
each column is used as the column heading.
However this column names could be completely
vague and meaningless.
• At such times, you may want to rename the column
heading with a more meaningful name. You do this
by using a column alias.
• A column alias is placed in the SELECT clause just beside
the column name and the AS keyword is introduced.
FORMAT:
SELECT column_name AS alias
FROM table_name;
EXAMPLE
• You would notice that when a column alias is used,
the column heading changed from employee_id to
staff code.
RULES
• A column alias could be used with or without the AS
keyword.
• When writing a column alias, that contains spaces, it
is necessary to quote them in double quotation
marks “”.
DESCRIBE
• The DESCRIBE keyword is used to show the
structure of a Schema object. It displays the
column_names, data-type and all other meta data.
FORMAT:
DESCRIBE table_name;
EXAMPLE:
• The oracle server returns a detailed description of
the structure of the specified table including the
column names and any constraint details.
REVISION QUESTION
1. What are the basic functions of a SELECT
statement?
2. Write a SELECT statement to display the content
of the jobs table.
3. Write a SELECT statement to display the
first_name column of the employees table.
4. DESCRIBE the locations table.