Lecture 1 at A Glance: Lecture No 2: Writing Basic SQL SELECT Statements
Lecture 1 at A Glance: Lecture No 2: Writing Basic SQL SELECT Statements
Lecture 1 at A Glance: Lecture No 2: Writing Basic SQL SELECT Statements
Lecture 1 At a Glance
In the last lecture we have completed following topics:
Objectives
After completing this lecture, you should be able to
do the following:
Join
Table 1 Table 2
4 Lecture No 2: Writing Basic SQL SELECT Statements
National Institute of Electronics
SQL*Plus iSQL*Plus
•Runs from Oracle Server and from •Runs using internet Explorer
any computer where Oracle Database from any computer on the network
client is installed
•No need to install Oracle client
hr
**
ora
SQL*Plus iSQL*Plus
Runs from Oracle Server and from Runs using internet Explorer
any computer where Oracle Database from any computer on the network
client is installed
No need to install Oracle client
hr
**
Explore HR Schema
… …
……
• SQL*Plus:
– Character and Date column headings are left- justified
– Number column headings are right-justified
– Default heading display: Uppercase
Arithmetic Expressions
Operator Description
+ Add
- Subtract
* Multiply
/ Divide
+ - * /
SELECT
SELECT first_name,
first_name, last_name,
last_name, salary,
salary, salary
salary ++ 300
300
FROM
FROM employees;
employees;
SELECT
SELECT first_name,
first_name, last_name,
last_name, salary,
salary, salary
salary -- 300
300
FROM
FROM employees;
employees;
SELECT
SELECT first_name,
first_name, last_name,
last_name, salary,
salary, salary
salary ** 22
FROM
FROM employees;
employees;
SELECT
SELECT first_name,
first_name, last_name,
last_name, salary,
salary, salary
salary // 1000
1000
FROM
FROM employees;
employees;
Operator Precedence
* / + -
• Multiplication and division take priority over addition
and subtraction.
Operator Precedence
SELECT
SELECT last_name,
last_name, salary,
salary, 12*salary+100
12*salary+100
FROM
FROM employees;
employees;
…
Using Parentheses
Parentheses are used to force prioritized evaluation and to clarify statements.
SELECT
SELECT last_name,
last_name, salary,
salary, 12*(salary+100)
12*(salary+100)
FROM
FROM employees;
employees;
…
20 Lecture No 2: Writing Basic SQL SELECT Statements
National Institute of Electronics
Null Values
in Arithmetic Expressions
Concatenation Operator
A concatenation operator:
SELECT
SELECT last_name||job_id
last_name||job_id AS
AS "Employees"
"Employees"
FROM
FROM employees;
employees;
Duplicate Rows
SQL statements
iSQL*Plus Oracle
Internet server
Browser
Formatted report
Client
Overview
of iSQL*Plus
Logging In to iSQL*Plus
1 7
2 3 4 5
DESC[RIBE]
DESC[RIBE] tablename
tablename
DESCRIBE
DESCRIBE employees
employees
Interacting with
Script Files
Interacting with
Script Files
1
D:\temp\emp_sql.htm
Interacting with
Script Files
DESCRIBE employees
SELECT employee_id, first_name, last_name, job_id 1
FROM employees;
3 2
Summary
In this lecture, we have covered following topics: