Oracle Database Quick Start
Overview
- 45 minutes to complete the prerequisites (Note: The
time to download Oracle Database software to your local
machine depends on the network. Therefore, it is not included
in the time specified to complete the prerequisites.)
- 1 hour to complete this Oracle by Example (OBE)
- Minimum of 1 GB of physical memory
- Sufficient paging space
- Appropriate service packs and patches
- Appropriate file system format
- Complete the OBE entitled Installing Oracle Database Software and Creating a Database.
- Complete the OBE entitled Getting Started with Oracle Enterprise Manager Express.
- If you have problems connecting to the listener, complete
the OBE entitled Using
the Listener Control Utility to Manage the Listener.
Purpose
In this tutorial, you learn about Oracle Database and
how to perform simple operations on tables.
Time to Complete
Approximately 1 hour and 45 minutes:
Introduction
In general, a database is a collection of data treated as a unit. A database management system (DBMS) stores, manages and retrieves a large amount of data in a multi-user environment so that many users can access the same data concurrently.
Oracle Database is a robust object relational database that provides efficient and effective solutions for database users such as delivering high performance, protecting users from unauthorized access, and enabling fast failure recovery.
Hardware and Software Requirements
The following is a list of hardware and software needed to install Oracle Database:
Prerequisites
Before starting this tutorial, you should install Oracle
Database.
Understanding the HR Sample Schema
- Tables: Basic units of data storage in an Oracle database. Here, data is stored in rows and columns. You define a table with a table name and a set of columns.
- Indexes: Performance-tuning methods for allowing faster retrieval of records.
- Views: Representations of SQL statements
that are stored in memory so that they can be reused.
- The REGIONS table contains rows that represent a region such as the Americas or Asia.
- The COUNTRIES table contains rows for countries, each of which is associated with a region.
- The LOCATIONS table contains the specific addresses for the offices, warehouses, or production sites of a company in a particular country.
- The DEPARTMENTS table contains details about the departments in which employees work. Each department may have a relationship representing the department manager in the EMPLOYEES table.
- The EMPLOYEES table contains details about each employee who works in a department. Some employees may not be assigned to a department.
- The JOBS table contains the job types that an employee can hold.
- The JOB_HISTORY table
contains an employee's job history.
A database schema is a collection of metadata that describes
the relationship between the data in a database. A schema can be
simply described as the "layout" of a database or the blueprint
that outlines how data is organized into tables.
Schema objects are database objects that contain data or that
govern or perform operations on data. By definition, each schema
object belongs to a specific schema. The following are commonly
used schema objects:
The Human Resources (HR) schema is part of the Oracle Sample Schemas that you can install with Oracle Database. The following is the entity-relationship diagram of the HR schema:
The schema contains the following tables:
Connecting to the HR Schema
In this section, you connect to Oracle Database by using the
SQL*Plus utility, and you unlock the HR schema.
Querying the HR Schema
- A SELECT clause, which specifies columns containing the values to be matched
- A FROM clause, which specifies the table containing the columns listed in the SELECT clause
In this section, you execute the SELECT statement to
query tables in the HR schema. You also use the ORDER
BY and WHERE clauses within the SELECT
statement to sort and restrict data in the result set.
Querying Tables
In this section, you execute the SELECT
statement to retrieve data from tables and views. You can
select rows and columns that you want to return in the
output. In its simplest form, a SELECT statement
must contain the following:
Syntax: SELECT {*|[DISTINCT]
column|expression [alias],...}
FROM
<table>;
Restricting Data
In this section, you use the WHERE clause to
restrict the rows that are returned from the SELECT
query. A WHERE clause contains a condition that
must be met. It directly follows the FROM
clause. If the condition is true, the row that meets the
condition is returned.
Sorting Data
In this section, you use the ORDER BY clause to
sort the rows that are retrieved from the SELECT
statement. You specify the column based on the rows that
must be sorted. You also specify the ASC keyword
to display rows in ascending order (default), and you
specify the DESC keyword to display
rows in descending order.
Creating a Schema
- The instance administrator
- A user with ADMIN privileges
- The object's owner
- System privilege: The right to perform a particular action on any object, such as, tables, views and indexes. Only the instance administrator or a user with the ADMIN privilege can assign or revoke system privileges.
- Object privilege: The right to
perform a particular action on an object or to access
another user's object. An object's owner has all object
privileges for that object and can assign object
privileges for that object to other database users.
- Create a table, a view, or an index that is owned by
any user in the database
- Alter a table, a view, or an index in the database
- Drop a table, a view, or an index in the database
- Insert values into a table
- Create a foreign key dependency for a table
- Select from a table
- Update a table
- Table: Basic unit of data storage in
a database. Within a table, data is stored in rows and
columns. You define a table with a table name, a set of
columns, a data type, and a width.
- Integrity constraints: Rules for columns in a table. You specify these rules to enforce data integrity within the columns for which they are defined. Basic constraints on Oracle Database include the following:
In this section, you create a schema named ONLINE_SHOPPE. This schema portrays an online store that operates with a customer base and commodities. Information about customers is stored in the CUSTOMERS table, information about commodities is stored in the COMMODITIES table and order details are stored in the ORDERS table.
Creating a User
Database administrators perform many tasks. One of their
more common tasks is creating database users and assigning
them unique usernames. After users log in to the database
with their username and password, they can issue database
SQL statements to create objects, query objects, and
manage the database.
Creating a user is a way to create a schema. In this section, you execute the CREATE USER statement to create and configure a database user.
Syntax: CREATE USER <USER> IDENTIFIED
BY <password>;
Assigning Privileges
When multiple users access database objects, you can
control the authorization of the objects with privileges.
Privileges control whether a user can modify an object
that is owned by another user. They are granted or revoked
either by:
In general, there are two types of privileges:
Here are a few of the basic system and object privileges:
System privileges:
Object privileges:
You use the GRANT statement to assign
privileges to users and roles. To assign privileges, you
must have been assigned either the ADMIN OPTION
or the GRANT ANY PRIVILEGE system privilege.
Syntax: GRANT <grant_privilege> TO
<user>;
Creating Tables
Before creating tables in the ONLINE_SHOPPE
schema, you should understand the concepts of tables
and integrity constraints.
In this section, you execute the CREATE TABLE
statement to create tables.
Syntax: CREATE TABLE [schema.]table
(column datatype [DEFAULT expr][, ...]);
Perform the following steps to create the CUSTOMERS,
COMMODITIES, and ORDERS tables in the
schema.
Inserting, Modifying, and Deleting
Records
In this section, you manipulate the records in the tables
that you created.
Undoing and Saving Records
In this section, you use the COMMIT and ROLLBACK
statements to change data permanently. You use the ROLLBACK
statement to undo the work that was performed in your
current transaction and you use the COMMIT
statement to save the work that was performed in your
current transaction.
Removing Tables
In this section, you execute the DROP TABLE statement to remove a table and its data from the database.
Syntax: DROP TABLE <table>;
Revoking Privileges
In this section, you execute the REVOKE
statement to revoke user and role system privileges. To
revoke a system privilege or a role, you must be assigned
the privilege with the ADMIN OPTION.
Syntax: REVOKE <revoke_privilege> FROM
<user>;
Summary
- Connect to the HR schema
- Query, restrict and sort data in the HR schema
- Create a schema
- Create and delete tables
- Insert, modify, and delete records in a table
- Assign and revoke privileges
- The course entitled Oracle
Database: SQL Workshop I
- The documentation entitled Oracle
Database Concepts
- Lead Curriculum Developer: Supriya Ananth
- Other Contributors: Nancy Greenberg, Swarnapriya Shridhar
In this tutorial, you learned how to:
Resources
To learn more about Oracle Database, refer to:
Credits
To navigate this Oracle by Example tutorial, note the following:
- Hide Header Buttons:
- Click the title to hide the buttons in the header. To show the buttons again, click the title again.
- Topic List:
- Click a topic to navigate to that section.
- Expand All Topics:
- Click the button to show or hide the details for the sections. By default, all topics are collapsed.
- Hide All Images:
- Click the button to show or hide the screenshots. By default, all images are displayed.
- Print:
- Click the button to print the content. The content that is currently displayed or hidden is printed.
To navigate to a particular section in this tutorial, select the topic from the list.