Expression Specification
An expression specifies a value to be used in a SQL operation.
An expression can consist of a primary or several primaries connected by arithmetic operators, comparison operators, string or binary operators, bit operators or any of the functions described in Functions. A primary is a signed or unsigned value derived from one of the items listed in the SQL syntax.
SQL syntax
{ColumnName
| ROWID | {? | :DynamicParameter
} |Function
|Constant
| (Expression
)}
Or:
[[+ |-] {ColumnName
| SYSDATE | TT_SYSDATE|GETDATE() | {? | :DynamicParameter
} |Function
|Constant
| {~ | + | -}Expression
}] [...]
Or:
Expression1
[& | | | ^ | + | / | * | - ]Expression2
Or:
Expression1
| |Expression2
Or:
Expression
Component | Description |
---|---|
|
Unary plus and unary minus Unary minus changes the sign of the primary. The default is to leave the sign unchanged. |
|
Name of a column from which a value is to be taken See "Names, Namespace and Parameters" for more information. |
|
Unique ID for each row stored in a table The rowid value can be retrieved through the |
|
A placeholder for a dynamic parameter The value of the dynamic parameter is supplied at runtime. |
|
A computed value See "Functions" for more information. |
|
A specific value See "Constants" for details. |
|
Any expression enclosed in parentheses |
|
The specified expressions
|
|
Multiplies two primaries |
|
Divides two primaries |
|
Adds two primaries |
|
Subtracts two primaries |
|
Bitwise Sets a bit to 1 if and only if both of the corresponding bits in |
|
Bitwise Sets a bit to 1 if one or both of the corresponding bits in |
|
Bitwise Takes only one |
|
Exclusive Sets the bit to 1 where the corresponding bits in its |
|
Concatenate operator Concatenates |
Description
-
Arithmetic operators can be used between numeric values. See "Numeric Data Types" for more information.
-
Arithmetic operators can also be used between datetime values and interval types. The result of a datetime expression is either a datetime data type or an interval data type.
-
Arithmetic operators cannot be applied to string values.
-
Elements in an expression are evaluated in the following order:
-
Functions and expressions in parentheses
-
Unary pluses and minuses
-
The
*
and/
operations -
The
+
and–
operations -
Elements of equal precedence are evaluated in left-to-right order
-
-
You can enclose expressions in parentheses to control the order of their evaluation. An example follows.
10 * 2 – 1 = 19 but 10 * (2 – 1) = 10
-
Type conversion, truncation, underflow, or overflow can occur when some expressions are evaluated. See "Data Types" for more information.
-
If either operand in a numeric expression is
NULL
, the result isNULL
. -
Since
NVL
takes two parameters, both designated as an "expression", TimesTen does not permitNULL
in either position. If there is aNULL
value in an expression, comparison operators and other predicates evaluate toNULL
. See Search Conditions for more information on evaluation of comparison operators and predicates containingNULL
values. TimesTen permits insertingNULL
, but in generalINSERT
takes only specific values, and not general expressions. -
The query optimizer and execution engine permit multiple rowid lookups when a predicate specifies a disjunct of rowid equalities or uses
IN
. For example, multiple fast rowid lookups are executed for:WHERE ROWID = :v1 OR ROWID = :v2
Or equivalently:
WHERE ROWID IN (:v1, :v2)
-
The
?
or:
DynamicParameter
can be used as a dynamic parameter in an expression.
Examples
This example shows a dynamic parameter in the WHERE
clause of any SELECT
statement:
SELECT * FROM purchasing.orders WHERE partnumber = ? AND ordernumber > ? ORDER BY ordernumber;
This example shows a dynamic parameter in the WHERE
and SET
clauses of an UPDATE
statement:
UPDATE purchasing.parts SET salesprice = :dynamicparameter1 WHERE partnumber = :dynamicparameter2;
This example shows a dynamic parameter in the WHERE
clause of a DELETE
statement:
DELETE FROM purchasing.orderitems WHERE itemnumber BETWEEN ? AND ?;
This example shows a dynamic parameter in the VALUES
clause of an INSERT
statement. In this example, both ?
and :
dynamicparameter
are used where :dynamicparameter1
corresponds to both the second and fourth columns of the purchasing.orderitems
table. Therefore, only four distinct dynamic parameters need to be passed to this expression with the second parameter used for both the second and fourth columns.
INSERT INTO purchasing.orderitems VALUES (?,:dynamicparameter1, :dynamicparameter2, :dynamicparameter1,?);
This example demonstrates that both ?
and :dynamicparameter
can be used in the same SQL statement and shows the semantic difference between repeating both types of dynamic parameters.
Following are examples of bitwise operators.
Command> SELECT 0x183D & 0x00FF FROM dual; < 003D > 1 row found. Command> SELECT ~255 FROM dual; < -256 > 1 row found. Command> SELECT 0x08 | 0x0F FROM dual; < 0F > 1 row found.