Information Modeling and Relational Databases: From Conceptual Analysis to Logical Design

11.9 SQL: Scalar Operators and Bag Functions

A scalar is a data value (e.g., a number, string, or date). This section provides a brief discussion of the scalar operators and bag functions that are available in SQL-89, as well as some of the further operators and functions included in SQL-92 and SQL:1999.

In SQL-89, the scalar operators are the four arithmetic operators +, -, *, and /. As unary operators, + and - provide the sign of the number (e.g., +3 or -3). If omitted, + is assumed (e.g., 3 = +3). As binary operators, + and - perform addition and subtraction. The binary operators * and / perform multiplication and division; they have no unary version. Each is a number-forming operator on numbers. Their operands may appear as column names, constants, function calls, or expressions formed from these by use of arithmetic operators and perhaps parentheses. Scalar expressions may be used as items in a select-list or a search condition.

Let s begin by seeing how these operators may be used to provide a simple calculator facility in SQL to compute the value of an arithmetic expression. We simply include in our database a dummy table with just one row, and then include the expression as the sole item in a select-list for this table. Some DBMSs have dummy tables built in, but let s create our own by issuing the command create table C...

UNLIMITED FREE
ACCESS
TO THE WORLD'S BEST IDEAS

SUBMIT
Already a GlobalSpec user? Log in.

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.

Customize Your GlobalSpec Experience

Category: Arithmetic Logic Units (ALU)
Finish!
Privacy Policy

This is embarrasing...

An error occurred while processing the form. Please try again in a few minutes.