Predicates ask questions; expressions compute the values those questions are about. In DB2 for z/OS, expressions combine columns, literals, functions, and operators—arithmetic, concatenation, comparisons, and Boolean connectives. This page maps the landscape: expressions, operators, comparisons, Boolean logic, and precedence.
An expression produces a value. Without operators, the expression is that value: a column name, a host variable, a string or number literal, a function result, or a scalar fullselect.
123456SELECT SALARY, :HV_SALARY, 'SALARY', MAX(SALARY), SALARY * 1.03 AS RAISED FROM HR.EMPLOYEE;
Expressions appear in SELECT lists, SET assignments, VALUES rows, ORDER BY, and nested inside predicates and CASE. The data type of the result follows Db2’s type resolution rules—promotion, casting, and function resolution (next pages) decide the final type.
Richer expression forms include CASE, CAST, array constructors, OLAP specifications, and sequence references. Start with simple arithmetic and concatenation; add the rest as you need them.
| Operators | Role |
|---|---|
| + − * / | Arithmetic on numbers / datetime durations |
| CONCAT / || | String concatenation |
| = <> < > <= >= | Comparisons (predicates) |
| AND OR NOT | Boolean combination of predicates |
Use +, −, *, and / on numeric operands (and certain datetime + duration patterns). Unary plus and minus set signs. Division by zero and numeric overflow raise errors according to product rules. Mixing SMALLINT with DECIMAL promotes types—see the casting and numeric-types pages.
12345SELECT EMPNO, SALARY + COALESCE(COMM, 0) AS TOTAL, SALARY * 1.10 AS AFTER_RAISE, (SALARY - 20000) / 12 AS MONTHLY_OVER_BASE FROM HR.EMPLOYEE;
String concatenation joins compatible strings. Prefer the keyword CONCAT over ||. Vertical bars (and some EBCDIC substitutes) can break when statements move across CCSIDs; CONCAT travels more safely. If either operand is null, the result is null.
12SELECT FIRSTNME CONCAT ' ' CONCAT LASTNAME AS FULL_NAME FROM HR.EMPLOYEE;
Character and binary strings do not concatenate with each other. Result length and type (CHAR vs VARCHAR vs CLOB, and graphic counterparts) follow documented combination tables.
Comparison operators (=, <>, <, >, <=, >=) compare two expressions and produce a predicate result—not a numeric “1/0” value in ordinary SQL. Operands must be compatible types (all numeric types are compatible with each other; strings compare with strings; datetimes with datetimes, with conversion rules).
123WHERE SALARY >= 50000 WHERE HIREDATE < CURRENT DATE WHERE LASTNAME <> FIRSTNME
Distinct types usually must match exactly or be cast before comparison. Constants are built-in types, so comparing a distinct-typed column to a literal often needs CAST.
AND, OR, and NOT combine predicate truth values into search conditions. They are not arithmetic operators: you do not write SALARY AND COMM to mean a numeric calculation. Under three-valued logic, UNKNOWN participates in the truth tables you met on the NULL page.
123WHERE WORKDEPT = 'A00' AND (SALARY > 60000 OR BONUS > 1000) AND NOT (COMM IS NULL);
When expressions mix operators without parentheses, precedence and associativity decide evaluation order. Arithmetic multiplies before it adds. Boolean NOT binds tighter than AND, which binds tighter than OR—but always parenthesize complex filters so humans (and future you) read the intent instantly.
| Level | Items |
|---|---|
| Highest (typical) | Parentheses ( … ) |
| Unary | + − (signs) |
| Multiply / divide | * / |
| Add / subtract | + − |
| Comparisons | = <> < > … |
| Boolean | NOT, then AND, then OR (use parentheses!) |
12345678-- 14, not 20 VALUES 2 + 3 * 4; -- Force addition first → 20 VALUES (2 + 3) * 4; -- Clarify Boolean intent WHERE (A = 1 OR B = 2) AND C = 3;
1234567SELECT EMPNO, FIRSTNME CONCAT ' ' CONCAT LASTNAME AS NAME, SALARY * 1.03 AS NEXT_SALARY FROM HR.EMPLOYEE WHERE WORKDEPT IN ('A00', 'B01') AND SALARY + COALESCE(COMM, 0) > 55000 ORDER BY NEXT_SALARY DESC;
The SELECT list uses concatenation and arithmetic expressions. The WHERE clause uses comparison and Boolean operators (plus an IN predicate). Precedence makes SALARY * 1.03 obvious; COALESCE protects the sum from null COMM.
An expression is a recipe that makes a number or a word: “take salary and multiply by one and a tiny bit.” Operators are the action words in the recipe—add, multiply, stick words together. Comparisons ask “is this pile bigger than that pile?” Boolean words like AND and OR glue those questions together: “is it red AND big?” Precedence is the rule about which action happens first when you forget to use parentheses—like always multiplying before adding in school math.
1. What is an expression in SQL?
2. Which operator concatenates strings in a portable way?
3. What is 2 + 3 * 4 in SQL arithmetic precedence?
4. How do comparison operators differ from Boolean operators?
5. What happens if either operand of concatenation is NULL?