Sei sulla pagina 1di 29

CHAPTER 1:

INTRODUCTION

Oracle SQL
SQL

• SQL, pronounced ‘Sequel’ or simply S-Q-L, is a


computer programming language that was
developed especially for querying relational
databases using a non-procedural approach.

• The term non-procedural means that you can


extract information by simply telling the system
what information is needed without telling how to
perform the data retrieval.
SQL
• Extracting information from the database by
using SQL is termed querying the database.

• SQL is a language that is fairly simple to learn


in terms of writing queries, but it has
considerable complexity because it is a very
powerful language.
DATA AND INFORMATION

• Information is derived from raw facts known as


data.
• Data have little meaning or usefulness to managers
unless they are organized in some logical manner.
• One of the most efficient ways to organize and
manage data is through the use of a database
management system (DBMS).
DBMS
• Common relational DBMS products are the Oracle
RDBMS, IBM’s DB2, Microsoft’s SQL Server,
and Microsoft’s desktop single user RDBMS
named Microsoft Access.

• A DBMS provides both systems development


professionals and information users with an easy-
to-use interface to their organization’s database.
DATA
• Two types of data are stored within a
database:

• User data: Data that must be stored by an


organization.
• System data: Data the database needs to
manage user data to manage itself. This is
also termed metadata, or the data about
data.
Relational Database

• The most common type of DBMS software in


use today is termed a relational DBMS or
RDBMS.
• A relational database stores data in the form of
tables.
• A table is defined as a collection of rows and
columns.
• The tables are formally known as relations; this
is where the relational database gets its name.
TABLE
• In the figure, rows represent records and
columns represent fields in a file processing
sense.
DATABASE MANAGEMENT SYSTEM
• A database management system (DBMS)
manages the data in a database.
• A DBMS is a collection of programs that
enables the users to create and maintain a
database.
• A DBMS also enables data to be shared;
information system users and managers can get
more information value from the same amount
of data when data sharing occurs.
ORACLE’S RELATIONAL DBMS
• Oracle Corporation’s RDBMS is one of the
widely used RDBMS products.
• An RDBMS performs all the basic functions of
the DBMS software along with a magnitude of
other functions that make the relational model
easier to understand and to implement.
• RDBMS provides services that allow
information systems professionals to easily
change the structure of a database.
ORACLE

The significant features of Oracle are:

• Security mechanisms
• Backup and recovery
• Space management
• Open connectivity
• Tools and applications
SQL AND ORACLE’S SQL*PLUS

• Data are manipulated by RDBMS users through


the use of special data manipulation language.
• Database structures can also be defined by the
use of data definition language.
• SQL is the most popular database language and
has commands that enable it to be used for both
manipulation and definition of databases.
SQL
• SQL is used by Oracle for all interaction with
the database. SQL statements fall into two
major categories:

– Data Definition Language (DDL): Set of SQL


commands that create and define objects in a
database.
– Data Manipulation Language (DML): Set of
SQL commands that allows users to
manipulate the data in a database.
SQL
• SQL is basically a free format language. This
means that there are no particular spacing rules
that must be followed when typing SQL
commands.
• SQL is a nonprocedural language. This means
that the user only has to specify the task for the
DBMS to complete, but not how the task is to
be completed. The RDBMS parses (converts)
the SQL commands and completes the task.
SQL*PLUS

Through SQL*PLUS users can:


• Enter, edit, store, retrieve, and run SQL
commands and PL/SQL blocks.
• Format, perform calculations on, store, and
print query results in the form of reports.
• List column definitions for any table.
• Access and copy data between SQL databases.
• Send messages to and accept responses from an
information system user.
RELATIONAL OPERATIONS

• SQL operations for creating new tables,


inserting table rows, updating table rows,
deleting table rows, and querying databases are
the primary means of interfacing with relational
databases.
• The SELECT statement is used primarily to
write queries that extract information from the
database which is a collection of related tables.
The SELECT Statement
• The power of SELECT statement comes from
its ability to combine data from many tables to
produce output in the form of a result table.
• A select statement can include or exclude
specific columns from one or more tables.
SELECT emp_ssn, emp_last_name
FROM employee;
EMP_SSN EMP_LAST_NAME
--------- -------------
999666666 Bordoloi
999555555 Joyner
999444444 Zhu
Selection Operation
• A selection operation selects a subset of rows in
a table (relation) that satisfies a selection
condition. That subset can range from no rows
to all rows in a table.

SELECT emp_ssn, emp_first_name


FROM employee
WHERE emp_ssn = '999111111';

EMP_SSN EMP_FIRST_NAME
--------- ---------------
999111111 Douglas
Join Operation
• A join operation combines data from two or
more tables based upon one or more common
column values.
• The relational join is a very powerful operation
because it allows users to investigate
relationships among data elements.
• The following SELECT statement displays
column information from both the employee
and department tables.
Example
The tables are joined upon values stored in the department
number columns named emp_dpt_number in the
employee table and dpt_no in the department table.
SELECT emp_ssn, emp_first_name, emp_last_name,
emp_dpt_number
FROM employee e, department d
WHERE e.emp_dpt_number = d.dpt_no;

EMP_SSN EMP_FIRST_NAME EMP_LAST_NAME EMP_DPT_NUMBER


--------- --------------- --------------- --------------
999666666 Bijoy Bordoloi 1
999555555 Suzanne Joyner 3
999444444 Waiman Zhu 7
more rows will be displayed . . .
SQL*PLUS
• SQL*PLUS enables the user to manipulate
SQL commands and to perform many
additional tasks as well.
• Through SQL*PLUS, a user can:

4. Enter, edit, store, and retrieve SQL commands.


5. Format, perform calculations on, store, and
print query results in the forms of reports.

contd
SQL*PLUS

2. List column definitions for any table.


3. Access and copy data between SQL databases.
4. Send messages to and accept responses from a
system user.
Starting SQL*PLUS
• The most common types used are either the
standard Oracle SQL*PLUS available for a
Windows-type interface or by connecting to an
Oracle database via a telnet session.
• The following Log On session is a connection to
an Oracle database stored on a Sun Microsystems
server running the Unix O/S.
• An SQL*PLUS session is begun by typing the
command sqlplus at the command prompt($) and
entering the username and password information.
contd
Log-On Screen
Exiting SQL*PLUS

• The SQL*PLUS session can be ended by


typing a command at the SQL prompt to
terminate the session.
• Two commands are available: exit or quit.
Either one of these can be used to terminate an
SQL*PLUS session.
Running (Executing) a Command File

• The command to run (execute) a command file


is:

SQL> START filename.sql

• A form of shorthand for the word “start” can be


used when executing a command file by
replacing “start” with the @ (“at” symbol).
Syntax Conventions

• Each select statement must follow precise


syntactical and structural rules.
• The following is the minimum structure and
syntax required for an SQL SELECT statement.

SELECT [DISTINCT | ALL] {* |


select_list}
FROM {table_name [alias] | view_name}
SQL Keywords

• Keywords are words that have a predefined


meaning in SQL.
• In practice, keywords may be entered in upper
or lower case letters.

SELECT *
FROM employee;

select *
from employee;
SQL Keywords
• In some cases keywords can be abbreviated.

DESCribe: can be entered as either DESC or


DESCRIBE.

Potrebbero piacerti anche