📅  最后修改于: 2023-12-03 15:00:31.339000             🧑  作者: Mango
Scalar expressions in DocumentDB SQL refer to a single value expression that returns a scalar value. In simpler words, it is an expression that returns a result of a single value, unlike a table expression that returns a set of values. Scalar expressions can be used in various ways in DocumentDB SQL queries.
The following are some examples of scalar expressions in DocumentDB SQL:
SELECT 4 + 5 -- returns 9
SELECT 4 - 5 -- returns -1
SELECT 4 * 5 -- returns 20
SELECT 4 / 5 -- returns 0.8
SELECT 4 > 5 -- returns false
SELECT 4 < 5 -- returns true
SELECT 4 = 5 -- returns false
SELECT 4 != 5 -- returns true
SELECT NOT(4 > 5) -- returns true
SELECT (4 > 5) OR (4 < 5) -- returns true
SELECT (4 > 5) AND (4 < 5) -- returns false
SELECT ABS(-4) -- returns 4
SELECT LOWER('HELLO') -- returns 'hello'
SELECT UPPER('world') -- returns 'WORLD'
SELECT 4 -- returns 4
SELECT 'hello' -- returns 'hello'
SELECT true -- returns true
Scalar expressions can be used in various parts of a DocumentDB SQL query like SELECT statements, WHERE clauses, ORDER BY clauses, etc. These expressions help in performing complex calculations, filtering data, and sorting results.
In conclusion, scalar expressions are a powerful and essential feature of DocumentDB SQL. They provide a concise and efficient way to perform arithmetic, comparisons, logical, and function operations on values. Programmers can leverage scalar expressions to build robust and scalable DocumentDB SQL queries.