(10.2.0)
Part No. B15917-01
This document discusses SQL operators used with Oracle Database Lite. Topics include:
Section 2.1, "SQL Operators Overview"
Section 2.2, "Arithmetic Operators"
Section 2.3, "Character Operators"
Section 2.4, "Comparison Operators"
Section 2.5, "Logical Operators"
Section 2.6, "Set Operators"
Section 2.7, "Other Operators"
An operator manipulates individual data items and returns a result. The data items are called operands or arguments . Operators are represented by special characters or by keywords. For example, the multiplication operator is represented by an asterisk (*) and the operator that tests for nulls is represented by the keywords IS NULL . There are two general classes of operators: unary and binary. Oracle Database Lite SQL also supports set operators.
A unary operator uses only one operand. A unary operator typically appears with its operand in the following format.
A binary operator uses two operands. A binary operator appears with its operands in the following format.
Set operators combine sets of rows returned by queries, instead of individual data items. All set operators have equal precedence. Oracle Database Lite supports the following set operators.
The levels of precedence among the Oracle Database Lite SQL operators from high to low are listed in Table 2-1 . Operators listed on the same line have the same level of precedence.
Table 2-1 Levels of Precedence of the Oracle Database Lite SQL Operators
Precedence Level | SQL Operator |
---|---|
1 | Unary + - arithmetic operators, PRIOR operator |
2 | * / arithmetic operators |
3 | Binary + - arithmetic operators, || character operators |
4 | All comparison operators |
5 | NOT logical operator |
6 | AND logical operator |
7 | OR logical operator |
Other operators with special formats accept more than two operands. If an operator receives a null operator, the result is always null. The only operator that does not follow this rule is CONCAT .
Arithmetic operators manipulate numeric operands. The '-' operator is also used in date arithmetic. Supported arithmetic operators are listed in Table 2-2 .
Table 2-2 Arithmetic Operators
Operator | Description | Example |
---|---|---|
+ (unary) | Makes operand positive | |
- (unary) | Negates operand | |
/ | Division (numbers and dates) | |
* | Multiplication | |
+ | Addition (numbers and dates) | |
- | Subtraction (numbers and dates) |
Character operators used in expressions to manipulate character strings are listed in Table 2-3 .
Table 2-3 Character Operators
Operator | Description | Example |
---|---|---|
|| | Concatenates character strings |
With Oracle Database Lite, you can concatenate character strings with the following results.
Concatenating two character strings results in another character string.
Oracle Database Lite preserves trailing blanks in character strings by concatenation, regardless of the strings' datatypes.
Oracle Database Lite provides the CONCAT character function as an alternative to the vertical bar operator. For example,
This returns the following output.
Oracle Database Lite treats zero-length character strings as nulls. When you concatenate a zero-length character string with another operand the result is always the other operand. A null value can only result from the concatenation of two null strings.
Comparison operators used in conditions that compare one expression with another are listed in Table 2-4 . The result of a comparison can be TRUE , FALSE , or UNKNOWN .
Table 2-4 Comparison Operators
Operator | Description | Example |
---|---|---|
= | Equality test. | |
!=, ^=, <> | Inequality test. | |
> | Greater than test. | |
< | Less than test. | |
>= | Greater than or equal to test. | |
<= | Less than or equal to test. | |
IN | "Equivalent to any member of" test. Equivalent to " ". | |
ANY/ SOME | Compares a value to each value in a list or returned by a query. Must be preceded by . Evaluates to if the query returns no rows. | |
NOT IN | Equivalent to " ". Evaluates to if any member of the set is . | |
ALL | Compares a value with every value in a list or returned by a query. Must be preceded by Evaluates to if the query returns no rows. | |
[NOT] BETWEEN x and y | [Not] greater than or equal to x and less than or equal to y. | |
EXISTS | if a sub-query returns at least one row. | |
x [NOT] LIKE y [ESCAPE z] | if x does [not] match the pattern y. Within y, the character "%" matches any string of zero or more characters except null. The character "_" matches any single character. Any character following is interpreted literally, useful when y contains a percent (%) or underscore (_). | |
IS [NOT] NULL | Tests for nulls. This is the only operator that should be used to test for nulls. |
|
Logical operators which manipulate the results of conditions are listed in Table 2-5 .
Table 2-5 Logical Operators
Operator | Description | Example |
---|---|---|
NOT | Returns if the following condition is . Returns if it is . If it is , it remains . |
|
AND | Returns if both component conditions are . Returns if either is ; otherwise returns . | |
OR | Returns if either component condition is . Returns if both are . Otherwise, returns . |
Set operators which combine the results of two queries into a single result are listed in Table 2-6 .
Table 2-6 Set Operators
Operator | Description | Example |
---|---|---|
Returns all distinct rows selected by either query. |
| |
Returns all rows selected by either query, including all duplicates. |
| |
and | Returns all distinct rows selected by both queries. |
|
Returns all distinct rows selected by the first query but not the second. |
|
Note: : The syntax for is supported, but it returns the same results as . |
Other operators used by Oracle Database Lite are listed in Table 2-7 .
Table 2-7 Other Operators
Operator | Description | Example |
---|---|---|
(+) | Indicates that the preceding column is the outer join column in a join. | |
PRIOR | Evaluates the following expression for the parent row of the current row in a hierarchical, or tree-structured query. In such a query, you must use this operator in the clause to define the relationship between the parent and child rows. |
IMAGES
VIDEO
COMMENTS
Languages making the former choice often use a colon-equals (:=) or ≔ to denote their assignment operator. Languages making the latter choice often use a double equals sign (==) to denote their boolean equality operator. Also check here: The assignment operator in PL/SQL is a colon plus an equal sign (:=). PL/SQL string literals are delimited ...
Assign a value (as part of a SET statement, or as part of the SET clause in an UPDATE statement) :=. Assignment operator. Causes the user variable on the left hand side of the operator to take on the value to its right. The value on the right hand side may be a literal value, another variable storing a value, or any legal expression that yields ...
General declaration syntax in PL/SQL uses ':='.Look below. variable_name datatype [NOT NULL := value ]; where, variable_name is the name of the variable. datatype is a valid PL/SQL datatype. NOT NULL is an optional specification on the variable. value or DEFAULT value is also an optional specification, where you can initialize a variable.
To assign a default value to a variable, you use the assignment operator (:=) or the DEFAULT keyword. The following example declares a variable named l_product_name with an initial value 'Laptop': DECLARE l_product_name VARCHAR2( 100) := 'Laptop'; BEGIN NULL; END; Code language: PostgreSQL SQL dialect and PL/pgSQL (pgsql)
The assignment operator is specific to PL/SQL. Its primary function is to set a variable equal to the value or expression on the other side of the operator. If we wanted to set the variable v_price equal to 5.5 * .90, we would write it as follows: An assignment can take place in the declaration section when a variable is first declared, or in ...
Assignment Statement. An assignment statement sets the current value of a variable, field, parameter, or element. The statement consists of an assignment target followed by the assignment operator and an expression. When the statement is executed, the expression is evaluated and the resulting value is stored in the target.
The Assignment Operator in Oracle is used to assign or compare a value to a column or a field of a table. The equal sign (=) is the assignment operator where the value on the right is assigned to the value on the left. It is also used to establish a relationship between a column heading and the expression that defines the values for the column.
Expression whose value is to be assigned to assignment_statement_target. expression and assignment_statement_target must have compatible data types. Collections with elements of the same type might not have the same data type. For the syntax of collection type definitions, see "Collection Variable Declaration".
In some SQL procedural languages, there are distinctions between assignment and comparison operators. Oracle PL/SQL uses := for assignment and = for comparison; MS SQL Server's Transact SQL uses only one operator for these purposes, =, as does IBM DB2 UDB.
Equal (=) Relational Operator in Oracle. The Equal (=) Operator in Oracle is used to check whether the two expressions are equal or not. If both the expressions are equal then the condition becomes true and will return the matched rows. For example, the following SQL Query will return all the records from the Employee table where the Gender is ...
This article provides a list of SQL operators, and can therefore be used as cheat sheet for SQL operators. ... Add Assignment operator. Adds two numbers and sets a value to the result of the operation. ... String Concatenation operator (DB2, Oracle, PostgreSQL, SQLite). String concatenation is the operation of joining character strings end-to ...
These changes document Community specific rules and Oracle's content moderation practices including use of automated tools, appeals process, and Oracle's contact details. If you object to any changes, you may request that your account be closed by contacting [email protected]. Your continued use of Oracle Communities ...
SQL Logical Operators. Operator. Description. Example. ALL. TRUE if all of the subquery values meet the condition. Try it. AND. TRUE if all the conditions separated by AND is TRUE.
You can define variables, called substitution variables, for repeated use in a single script by using the SQL*Plus DEFINE command.Note that you can also define substitution variables to use in titles and to save your keystrokes (by defining a long string as the value for a variable with a short name).. DEFINE L_NAME = "SMITH" (CHAR) To list all substitution variable definitions, enter DEFINE ...
Arithmetic Operator Addition (+) Example: Display salary of employees with 2000 increments in their salary. SELECT ID, Name, Salary, Salary + 2000 "Incremented salary" FROM Employee; Explanation: In the Employee table every employee's salary sums it 2000. When you execute the above query, you will get the following output.
2.1 SQL Operators Overview. An operator manipulates individual data items and returns a result. The data items are called operands or arguments. Operators are represented by special characters or by keywords. For example, the multiplication operator is represented by an asterisk (*) and the operator that tests for nulls is represented by the ...
The CASE expression is like a more flexible version of the DECODE function. The value match CASE expression, or simple CASE expression, compares the value of the expression (DEPTNO), with the list of comparison expressions (10 - 40). Once it finds a match, the associated value is returned. The optional ELSE clause allows you to deal with ...
Summary: in this tutorial, you will learn how to use the Oracle CASE expression to add if-else logic to the SQL statements.. Introduction to Oracle CASE expression. Oracle CASE expression allows you to add if-else logic to SQL statements without having to call a procedure.The CASE expression evaluates a list of conditions and returns one of the multiple possible results.
The same could be written using IF in PL/SQL: SQL> SET serveroutput ON SQL> DECLARE 2 lv_var1 VARCHAR2(500); 3 lv_var2 VARCHAR2(20); 4 ld_date DATE; 5 BEGIN 6 ld_date := SYSDATE; 7 lv_var2 := 'sample value'; 8 IF ld_date IS NOT NULL THEN 9 lv_var1 := lv_var2; 10 END IF; 11 dbms_output.put_line(lv_var1); 12 END; 13 / sample value PL/SQL ...
update TABLENAME set COLUMN1 += ?,COLUMN2 += ? You can also combine the arithmetic operators with the simple assignment operator to create compound assignments. For example, x+=1; If not, is there an enhancement of such requirement? This isn't duplicate of similar PLSQL question, I ask about Oracle SQL. sql.