Beruflich Dokumente
Kultur Dokumente
Objectives
Learn how to connect to Oracle 11g (client/server and
Personal)
Create the initial database
Learn database objects and SQL commands and components
Identify keywords, mandatory clauses, and optional clauses in
a SELECT statement
Select and view one/all columns of a table
Display multiple columns of a table
Use a column alias to clarify the contents of a particular
column
Perform basic arithmetic operations in the SELECT clause
Remove duplicate lists using either the DISTINCT or
UNIQUE keyword
Use concatenation to combine fields, literals, and other data
Dr. Chen, Business Database Systems (Oracle)
type exit
to quit the
system
click on
jepson-oracle
#1
sbaora11
#2
click on TNS
YOUR TURN
How to Access Your Oracle11g Account
User Name: <your lastname>
Password: <> <BMIS441> [case sensitive]
jepson-oracle
sbaora11
12
Tables
Views
Stored programs, etc.
14
SQL Components
ORACLE
(SQL Components)
DDL
DML
D.B.
DCL
(Create Table structure
and insert database)
Dr. Chen, Business Database Systems (Oracle)
16
DDL Commands
Used to create and modify the structure of
database objects
CREATE
ALTER
DROP
GRANT
REVOKE
17
DML Commands
Used to insert, view, and modify database data
INSERT
UPDATE
DELETE
SELECT
18
19
Scripts
Scripts are simply files that contain a sequence of
SQL and/or PL/SQL commands that can be
executed in SQL*Plus.
Note:
SQL and PL/SQL(to be introduced) are two
languages Oracle uses.
SQL*Plus is the tool we use to access Oracle.
SQL*Plus can execute both SQL and PL/SQL
commands plus it has its own commands.
20
Class Exercise
Create a new folder on c:\ as follows:
c:\oradata\chapter2
Download all files in chapter 2 from Bb (under
Course Documents) into c:\oradata\chapter2\
Logon to SQL*Plus and type the following
command (not on SQL Developer)
SQL> start c:\oradata\chapter2\JLDB_Build.sql
or,
SQL> @ c:\oradata\chapter2\JLDB_Build.sql
SQL> SELECT * FROM publisher;
Dr. Chen, Business Database Systems (Oracle)
21
22
23
25
30
31
32
33
14-DEC-05
18.75
14.2
37.8
04-JUN-03
31.4
28-FEB-04
12.5
31-DEC-05
47.25
More example
-- chapter 2, Figure 2-17; p. 44
SELECT DISTINCT state, city
FROM customers;
Using Concatenation
You can combine data
with a string literal
Use the concatenation
operator, ||
It allows the use of
column aliases
38
14-DEC-05
18.75
14.2
37.8
04-JUN-03
31.4
28-FEB-04
12.5
31-DEC-05
47.25
41
PUBDATE
ID
COST
RETAIL
DISCOUNT CATEGORY
--------- --- -------- -------- ---------- -----------21-JAN-05
4
$18.75
$30.95
FITNESS
14-DEC-05
$14.20
$22.00
FAMILY LIFE
18-MAR-06
$37.80
$59.95
3 CHILDREN
04-JUN-03
$31.40
$55.95
COMPUTER
28-FEB-04
$12.50
$19.95
COOKING
31-DEC-05
$47.25
$75.95
3.8 COMPUTER
21-JAN-05
$21.80
$25.00
COMPUTER
01-MAR-06
$37.90
$54.50
COMPUTER
17-JUL-04
$48.00
$89.95
11-SEP-04
$19.00
$28.75
COOKING
08-NOV-05
$5.32
$8.95
11-NOV-06
$17.85
$29.95
09-MAY-03
$15.40
$31.95
CHILDREN
1.5 SELF HELP
BUSINESS
PUBDATE
ID
COST
RETAIL
DISCOUNT CATEGORY
--------- --- -------- -------- ---------- -----------01-MAY-05
5
$21.85
$39.95
LITERATURE
14 rows selected.
Break !
Hands-On Assignments
In class exercise (p.54)
- #2
- see spool instruction on the next slide
HW
(Odd numbers only (pp.54-55), but do #1 at the end as it will affect the
rest of problems)
- run the following two commands:
Start c:\oradata\chapter2\JLDB_Drop.sql
Start c:\oradata\chapter2\JLDB_Build.sql
Output should be formatted in a very good manner.
Scripting file name: Oracle_ch2_Lname_Fname.sql
Spooled file name: Oracle_ch2_Spool_Lname_Fname.txt
49
Summary
A basic query in Oracle 11g SQL includes the
SELECT and FROM clauses, the only mandatory
clauses in a SELECT statement
To view all columns in the table, specify an
asterisk (*) or list all of the column names
individually in the SELECT clause
To display a specific column or set of columns,
list the column names in the SELECT clause (in
the order in which you want them to appear)
When listing column names in the SELECT
clause, a comma must separate column names
Dr. Chen, Business Database Systems (Oracle)
50
Summary (continued)
A column alias can be used to clarify the contents
of a particular column; if the alias contains
spaces or special symbols, or if you want to
display the column with any lowercase letters,
you must enclose the column alias in double
quotation marks (" ")
Indicate the table name following the FROM
keyword
Basic arithmetic operations can be performed in
the SELECT clause
NULL values indicate an absence of a value
Dr. Chen, Business Database Systems (Oracle)
51
Summary (continued)
To remove duplicate listings, include either the
DISTINCT or UNIQUE keyword
To specify which table contains the desired
columns, you must list the name of the table after
the keyword FROM
52
Dr. Chen, Business Database Systems (Oracle)
52