

The Oracle/PLSQL DECODE function has the functionality of an IF-THEN-ELSE statement.

If expr is null, then Oracle returns the result of the first search that is also null. Oracle / PLSQL: DECODE Function Description. In a DECODE function, Oracle considers two nulls to be equivalent. If the first result has the data type CHAR or if the first result is null, then Oracle converts the return value to the data type VARCHAR2.
Sql decode code#
Oracle automatically converts the return value to the same data type as the first result. SELECT DECODE (Letters, First,1, Second,2, Third,3, 0) AS LN FROM LettersTable In SQL Server the equivalent code is CASE statement. Oracle automatically converts expr and each search value to the data type of the first search value before comparing. Description: DECODE is a shortcut for the so-called simple CASE construct, in which a given expression is. Consequently, Oracle never evaluates a search if a previous search is equal to expr. The database evaluates each search value only before comparing it to expr, rather than evaluating all search values before comparing any of them with expr. Oracle Database uses short-circuit evaluation. The search, result, and default values can be derived from expressions.

If the first search-result pair are numeric, then Oracle compares all search-result expressions and the first expr to determine the argument with the highest numeric precedence, implicitly converts the remaining arguments to that data type, and returns that data type. The string returned is of VARCHAR2 data type and is in the same character set as the first result parameter. expr, search, and result can be any of the data types CHAR, VARCHAR2, NCHAR, or NVARCHAR2. If expr and search are character data, then Oracle compares them using nonpadded comparison semantics. The arguments can be any of the numeric types ( NUMBER, BINARY_FLOAT, or BINARY_DOUBLE) or character types. Users can also beautify and remove the comments from SQL. It supports Standard SQL, Couchbase N1QL, IBM DB2, MariaDB, and Oracle SQL & PL/SQL. Click on the URL button, Enter URL and Submit. MYSQL Formatter allows loading the SQL URL to beautify. If default is omitted, then Oracle returns null. This Query Formatter helps to beautify your SQL data instantly. If no match is found, then Oracle returns default. If expr is equal to a search, then Oracle Database returns the corresponding result. Examplesįrom MariaDB 10.3.DECODE compares expr to each search value one by one. The select expression is typically a column, but can be a subquery, literal, or other expression. If no matches are found, the default expression is returned, or NULL if no default is provided.ĭECODE_ORACLE is a synonym for the Oracle-mode version of the function, and is available in all modes. The search expressions are compared to this select expression, and if there is a match then DECODE returns the result that corresponds to that search expression.

If it finds a match, the corresponding result expression is returned. If the expression is the same as search, result is returned. The DECODE function decodes expression after comparing it to each search value. In Oracle mode from MariaDB 10.3.2, DECODE compares expr to the search expressions, in order. The DECODE function decodes an expression in a way similar to the IF-THEN-ELSE logic used in various languages. The resulting string will be the original string only if pass_str is the same. crypt_str should be a string returned from ENCODE(). In the default mode, DECODE decrypts the encrypted string crypt_str using pass_str as the In all modes from MariaDB 10.3.2: DECODE_ORACLE(expr, search_expr, result_expr ) In Oracle mode from MariaDB 10.3.2: DECODE(expr, search_expr, result_expr )
