Αποτελέσματα Αναζήτησης
You can rewrite it to use the ELSE condition of a CASE: SELECT status, CASE status WHEN 'i' THEN 'Inactive' WHEN 't' THEN 'Terminated' ELSE 'Active' END AS StatusText FROM stage.tst
For example, you can use the CASE expression in statements such as SELECT, UPDATE, or DELETE, and in clauses like SELECT, WHERE, HAVING, and ORDDER BY. Oracle CASE expression has two formats: the simple CASE expression and the searched CASE expression. Both formats support an optional ELSE clause.
The syntax for the CASE statement in Oracle/PLSQL is: CASE [ expression ] WHEN condition_1 THEN result_1 WHEN condition_2 THEN result_2 ... WHEN condition_n THEN result_n ELSE result END Parameters or Arguments expression Optional. It is the value that you are comparing to the list of conditions.
In a simple CASE expression, Oracle Database searches for the first WHEN... THEN pair for which expr is equal to comparison_expr and returns return_expr. If none of the WHEN... THEN pairs meet this condition, and an ELSE clause exists, then Oracle returns else_expr. Otherwise, Oracle returns null.
Is there a "better" way to rewrite a SELECT clause where multiple columns use the same CASE WHEN conditions so that the conditions are only checked once? See the example below.
The following example shows a simple CASE statement. Notice that you can use multiple statements after a WHEN clause, and that the expression in the WHEN clause can be a literal, variable, function call, or any other kind of expression. DECLARE. n number := 2; BEGIN. CASE n. WHEN 1 THEN dbms_output.put_line('n = 1');
26 Ιαν 2018 · The CASE statement is conditional flow control syntax. Many languages have this feature. Oracle has implemented it in both PL/SQL and into the SQL engine. In PL/SQL, there are two flavors. First, the CASE statement evaluates the contents of a variable and returns a value (implemented as a function).