Writing Basic
SQL Statements
Basic SELECT Statement
SQL> SELECT *
2 FROM dept;
DEPTNO LOC
--------- -------------
10 NEW YORK
20 DALLAS
30 CHICAGO
40 BOSTON
Arithmetic Expressions
• Create expressions on NUMBER and
DATE data by using arithmetic
operators.
Operator Description
+ Add
- Subtract
* Multiply
/ Divide
Using Arithmetic Operators
SQL> SELECT ename, sal, sal+300
2 FROM emp;
NAME 12*SAL+COMM
---------- -----------
KING
Using Column Aliases
SQL> SELECT ename AS name, sal salary
2 FROM emp;
NAME SALARY
------------- ---------
...
Employees
-------------------
KINGPRESIDENT
BLAKEMANAGER
CLARKMANAGER
JONESMANAGER
MARTINSALESMAN
ALLENSALESMAN
...
14 rows selected.
Literal Character Strings
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
• 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
Eliminate duplicate rows by using the
DISTINCT keyword in the SELECT clause.
SQL> SELECT DISTINCT deptno
2 FROM emp;
DEPTNO
---------
10
20
30
Displaying Table Structure