Operators

An operator is a symbol specifying an action that is performed on one or more expressions. Operators are used most often in DELETE , INSERT, SELECT, or UPDATE statements, but also are 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 Microsoft SQL Server

Comparison operators

Supported by all databases

Logical operators

Supported by DB2, Oracle, SQL Server, and PostgreSQL

Unary operators

Supported by DB2, Oracle, and SQL Server

Arithmetic operators

Arithmetic operators perform mathematical operations on two expressions of any datatypes 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 DB2, Oracle, and SQL Server, the + and - operators also can be used to perform 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 SQL Server, the keyword AS may serve as an operator for assigning table- or column-heading aliases.

Bitwise operators ...

Get SQL in a Nutshell, 2nd 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.