Lecture03 WritingBasicSQLStatements
Lecture03 WritingBasicSQLStatements
Introduction to Database
Lecture 03:
Writing Basic SQL Statements
Learning Objectives
2
To know about:
The capabilities of SQL SELECT statements
The execution of a basic SELECT statement
The Difference between SQL statements and
SQL*Plus commands
Capabilities of SQL SELECT Statements
3
Selection Projection
Table 1 Table 1
Join
Table 1 Table 2
Basic SELECT Statement
4
SQL> SELECT *
2 FROM dept;
DEPTNO LOC
--------- -------------
10 NEW YORK
20 DALLAS
30 CHICAGO
40 BOSTON
Column Heading Defaults
8
• Default justification
Left: Date and character data
Right: Numeric data
• Default display
Uppercase
Arithmetic Expressions
9
Operator Description
+ Add
- Subtract
* Multiply
/ Divide
Using Arithmetic Operators
10
_
* / +
• Multiplication and division take priority over
addition and subtraction.
• Operators of the same priority are evaluated
from left to right.
• Parentheses are used to force prioritized
evaluation and to clarify statements.
Operator Precedence
12
ENAME 12*SAL+COMM
---------- -----------
KING
Defining a Column Alias
16
NAME SALARY
------------- ---------
...
Employees
-------------------
KINGPRESIDENT
BLAKEMANAGER
CLARKMANAGER
JONESMANAGER
MARTINSALESMAN
ALLENSALESMAN
...
14 rows selected.
Literal Character Strings
20
Employee Details
-------------------------
KING is a PRESIDENT
BLAKE is a MANAGER
CLARK is a MANAGER
JONES is a MANAGER
MARTIN is a SALESMAN
...
14 rows selected.
Duplicate Rows
22
The default display of queries is all rows,
including duplicate rows.
SQL> SELECT deptno
2 FROM emp;
DEPTNO
---------
10
30
10
20
...
14 rows selected.
Eliminating Duplicate Rows
23
DEPTNO
---------
10
20
30
SQL
24
SQL
-> SQL is a command language for communication with the
Oracle Server.
Features of SQL
-> Can be used by a range of users, including those with
little or no programming experience
-> Is an English-like language
SQL*Plus
25
SQL*Plus
->SQL*Plus is an Oracle tool that recognizes and submits
SQL statements to the Oracle Server for execution and
contains its own command language.
Features of SQL*Plus
->Accepts SQL input from files
->Provides a line editor for modifying SQL statements
SQL Statements Versus SQL*Plus Commands
26
SQL
• A language
• ANSI standard
• Keyword cannot be
abbreviated
SQL*Plus
• An environment
• Oracle proprietary
• Keywords can be
abbreviated
Application of SQL*Plus
27
DESC[RIBE] tablename
THANK YOU