Operators

An operator is a symbol specifying an action to be performed on one or more expressions. Operators are used most often in DELETE, INSERT, SELECT, and UPDATE statements, but they are also used frequently in the creation of database objects such as stored procedures, functions, triggers, and views.

Operators typically fall into these categories:

Arithmetic operators

Supported by all databases

Assignment operators

Supported by all databases

Bitwise operators

Supported by MySQL and SQL Server

Comparison operators

Supported by all databases

Logical operators

Supported by all databases

Unary operators

Supported by MySQL, Oracle, and SQL Server

Arithmetic operators

Arithmetic operators perform mathematical operations on two expressions of any datatype in the numeric datatype category. See Table 2-2 for a listing of the arithmetic operators.

Table 2-2. Arithmetic operators

Arithmetic operator

Meaning

+

Addition

Subtraction

*

Multiplication

/

Division

%

Modula (SQL Server only); returns the remainder of a division operation as an integer value

Tip

In MySQL, Oracle, and SQL Server, the + and operators can be used to perform arithmetic operations on date values.

The various platforms also offer their own unique methods for performing arithmetic operations on date values.

Assignment operators

Except in Oracle, which uses :=, the assignment operator (=) assigns a value to a variable or the alias of a column heading. In all of the database platforms covered in this text, the keyword AS may serve as an operator ...

Get SQL in a Nutshell, 3rd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.