basic sql statements oracle/sql plus commands
DESCRIPTION
Basic SQL Statements Oracle/SQL Plus Commands. Kroenke , 11 th ed., Chapter Two. Relational Database Concept. Model proposed E. F. Codd 1970 Basis for Relational Database Management Systems (RDMS) Basis for Oracle. The Key Characteristic of Databases: Related Tables. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/1.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
1
Basic SQL StatementsOracle/SQL Plus
Commands
Basic SQL StatementsOracle/SQL Plus
CommandsKroenke, 11th ed., Chapter Two
![Page 2: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/2.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
2
Relational Database Concept
• Model proposed– E. F. Codd– 1970
• Basis for Relational Database Management Systems (RDMS)
• Basis for Oracle
![Page 3: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/3.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
3
The Key Characteristic of Databases: Related Tables
![Page 4: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/4.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
4
Relational Database Definition
A self-describing collection of integrated relations.
Table: EMP Table: DEPT
DEPTNO DNAME LOC
10 ACCOUNTING NEW YORK
20 RESEARCH DALLAS
30 SALES CHICAGO
40 OPERATIONS BOSTON
EMPNO ENAME JOB DEPTNO
7839 KING PRESIDENT 10
7698 BLAKE MANAGER 30
7782 CLARK MANAGER 10
7566 JONES MANAGER 20
![Page 5: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/5.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
5
The Relational Model• Collection of objects or relations to
store data & describe the database.
• Set of operators to act on relations• Data integrity constraints to
govern related tables
![Page 6: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/6.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
6
Structured Query Language
• SQL(sequel)• Communicate with server to
– Access,– Manipulate, and– Control data
![Page 7: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/7.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
7
SELECT Statements
• Access Data• Produce tables
![Page 8: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/8.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
8
Capabilities of SELECT Statements
• Selection: returns rows restricted by some criteria
• Projection: returns specified columns
• Join: brings together rows in different tables.
![Page 9: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/9.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
9
Capabilities of SQL SELECT Statements
Selection Projection
Table 1 Table 1
![Page 10: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/10.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
10
Capabilities of SQL SELECT Statements
Join
Table 1
Table 2
![Page 11: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/11.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
11
Relational Algebra Module
![Page 12: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/12.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
12
The Results of an SQL SELECT Statement
• Is a table!!!• Never puts stuff into existing
tables
![Page 13: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/13.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
13
Basic SELECT Statement
• SELECT identifies what columns.• FROM identifies which table.
SELECT [DISTINCT] {*, column [alias], . . .}FROM table;
![Page 14: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/14.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
14
Finding Oracle• Programming Applications folder
on desktop• Oracle – OraDB11g-home1 folder• Application Development folder• SQL Plus
![Page 15: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/15.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
15
To Log On
tiger
![Page 16: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/16.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
16
Some Uses for Spool Files
• Can be viewed in NotePad or Word• Can be edited to create the same
changes on another computer– Delete everything except SQL
statements– At home, run the edited file.
• Start fullpathfilename
![Page 17: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/17.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
17
Using the spool file Look at the
file name (no spaces in the
path)
![Page 18: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/18.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
18
Column Heading Defaults
of Three Data Types• Date and character data
– Left justified– Upper case– Date DD-MON-YY
• Numeric data– Right justified– Upper case
![Page 19: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/19.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
19
Arithmetic Expressions
• Create new values • From base table data• Do not change base table data
![Page 20: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/20.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
20
Operator Precedence Like Algebra
• Evaluate * and / before + and -• Evaluate from left to right• Parenthesis override • No exponentiation operator exists
![Page 21: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/21.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
21
Null Values• Unavailable, unassigned,
inapplicable• NOT the same as zero or blank• Defined within the context of
specific database• Nvl(column, value)
![Page 22: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/22.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
22
Column Aliases• Two formats
– SELECT column AS alias– SELECT column alias
• Be consistent in style• Double quotes around the alias
allow– Mixed case– Spaces
![Page 23: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/23.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
23
DESCRIBE tablename• Describes structure of existing
table• A SQL Plus command
![Page 24: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/24.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
24
Datatype Description
NUMBER(p.s) Number value having a maximum number of digits p . the number of digits to the right of the decimal point s
VARCHAR2(s) Variable-length character value of maximum size s
DATE Date and time value between Jan. 1, 4712 B.C. and Dec. 31, 9999 A.D.
CHAR(s) Fixed-length character value of size s
![Page 25: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/25.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
25
SQL*Plus File Commands
• SAVE filename• GET filename• START filename• @ filename• EDIT filename• SPOOL filename• EXIT
![Page 26: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/26.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
26
SQL Statements vs SQL*Plus Commands
SQL• A language• ANSI standard• Keyword NOT
abbreviated• Statements
manipulate data & table definitions in
DB
SQL*Plus• An
environment• Oracle
proprietary• Keywords can
be abbreviated• Commands do
NOT manipulate table structure or values in DB
![Page 27: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/27.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
27
Server
Buffer
SQL*Plus
-----------------------
SQL Statements SQL Statements
SQL*Plus Commands
Query Results
Formatted Report
![Page 28: Basic SQL Statements Oracle/SQL Plus Commands](https://reader033.vdocuments.net/reader033/viewer/2022061516/56815a42550346895dc7788b/html5/thumbnails/28.jpg)
Much from Introduction to Oracle:SQL and PL/SQL, Oracle University
28
Do Practice 1• Practice 1 – Basic SQL SELECT Statements.doc