Datasheet
20
Chapter 1
Introducing SQL
Operators and Literals
An operator is a manipulator that is applied to a data item in order to return a result. Spe-
cial characters represent different operations in Oracle (
+ represents addition, for example).
Operators are commonly used in all programming environments, and you should already
be familiar with the following operators, which may be classified into two types:
Unary operator A unary operator has only one operand. Examples are +2 and –5. They
have the format <operator><operand>.
Binary operator A binary operator has two operands. Examples are 5+4 and 7*5. They
have the format <operand1><operator><operand2>. You can insert spaces between the
operand and operator to improve readability.
I’ll now discuss the various types of operators available in Oracle.
Arithmetic Operators
Arithmetic operators operate on numeric values. Table 1.4 shows the various arithmetic
operators in Oracle and how to use them.
TABLE 1.4 Arithmetic Operators
Operator Purpose Example
+ - Unary operators: Use to represent positive or negative data item.
For positive items, the + is optional.
-234.44
+
Addition: Use to add two data items or expressions. 2+4
-
Subtraction: Use to find the difference between two data items or
expressions.
20.4-2
*
Multiplication: Use to multiply two data items or expressions. 5*10
/
Division: Use to divide a data item or expression with another. 8.4/2
Do not use two hyphens (--) to represent double negation; use a space or
parentheses in between, as in
-(-20). Two hyphens represent the begin-
ning of a comment in SQL.
Concatenation Operator
The concatenation operator is used to concatenate or join two character (text) strings. The
result of concatenation is another character string. Concatenating a zero-length string (
‘’)
95127c01.indd 20 2/18/09 6:37:08 AM