oracle/plsql case条件语句的用法
本文章要介绍关于oracle/plsql case条件语句的用法,它和mysql mssql都差不多,好了费话不说多了需要的学同可以看看吧。
本文章要介绍关于oracle/plsql case条件语句的用法,它和mysql mssql都差不多,好了费话不说多了需要的学同可以看看吧。语句语法
代码如下 | 复制代码 |
CASE [ expression ] |
expression 可选的。它的价值,你比较的条件清单。 (即:condition_1,condition_2,... condition_n)
condition_1到condition_n都必须是相同的数据类型。条件评估中列出的顺序。一个条件是一旦发现是真实的,case语句将返回的结果和不评价任何进一步的条件。
result_1到result_n都必须是相同的数据类型。这是返回的值一个条件是,一旦发现是真的。
注意:
如果没有条件为真,那么case语句将返回在ELSE子句里的值。
如果省略了ELSE子句和任何条件发现是真的,那么case语句将返回NULL。
最多可以有255在case语句比较。时,每个...条款被认为是2比较。
Applies To:
Oracle 9i, Oracle 10g, Oracle 11g
实例
你可以使用case语句在SQL语句如下:(包括表达式子句)
代码如下 | 复制代码 |
table_name, |
或者你可以写SQL语句,使用这样的情况下声明:(省略了表达式子句)
代码如下 | 复制代码 |
select table_name, |
上述两个案例语句以下的IF - THEN- ELSE语句是等价的:
代码如下 | 复制代码 |
IF owner = 'SYS' THEN ELSIF owner = 'SYSTEM' THEN ELSE END IF; |
case语句会比较每一位业主的价值,一个接一个。
需要注意的一点是,在case语句的else子句是可选的的。你可以省略。让我们看看上面的SQL语句与ELSE子句省略。
您的SQL语句如下所示:
代码如下 | 复制代码 |
select table_name, |
实例
下面就是一个例子,演示了如何使用case语句来比较不同条件下:
代码如下 | 复制代码 |
select CASE WHEN a WHEN d END from suppliers; |

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











In this section, we will see how to check whether a number is odd or even without using any conditional statements like <, <=, !=, >, >=, ==. We can easily check if the number is odd or even by using conditional statement. We can divide the number by 2 and check if the remainder is 0. If 0, it is an even number. Otherwise, we can AND the number with 1. If the answer is 0, it is an even number, otherwise it is an odd number. Conditional statements cannot be used here. We'll see two different ways to check whether an odd or even number is present. Method 1 Here we will create an array of strings. The index 0 position will hold "even" and the index 1 position will hold "odd". We can divide numbers

Getting Started with Python Code: 5 Essential Examples for Learning Python is a simple and easy-to-learn high-level programming language that is widely used in data analysis, machine learning, web crawlers and other fields. For beginners, it is important to master some basic Python code. This article will introduce 5 simple example codes to help beginners quickly get started with Python programming. Print Hello,World!print("Hello,World!") This is Python

Here we will see how to write a C program that can print numbers from 1 to 100 without using any kind of loop. This problem can be solved using recursion. We will create a function that will be called recursively. We know that recursive functions basically have two parts. Operations such as base cases and recursive calls. In this function, the base case is that parameter n is greater than 1. The function will be called recursively until 1 is reached. Now finally it will print the value of n. This way the entire system generates numbers. Sample code #include<stdio.h>voidgenerate_numbers(intn){if(n>1){generate_nu

As a high-level programming language, C++ has a variety of flow control statements to implement the decision-making structure and loop structure of the program. Among them, the conditional statement is one of the most commonly used statements in C++ programming. It determines the execution path of the program by judging whether the condition is met. This article will introduce the usage and examples of conditional statements in C++ in detail to help readers better understand and apply this syntax. 1. Basic syntax of conditional statements Conditional statements in C++ mainly include three types: if statement, ifelse statement and switch statement. their basic language

Three forms of conditional statements: 1. if statement: the syntax is "if (condition) {execute statement}", if the condition is true, the statement is executed; 2. if-else statement: the syntax is "if (condition) {execute Statement 1 } else {Execute statement 2 }", if the condition is true, execute statement 1; otherwise, execute statement 2; 3, switch statement, etc.

Conditional statements in the Python language are an important programming concept that are often used to control the flow of the program and determine whether to perform different operations under different circumstances. In Python, commonly used conditional statements include if statements and if-else statements. This article will introduce how to use conditional statements in Python. 1. Basic usage of if statement The if statement is one of the most commonly used conditional statements in Python. It is used to execute a block of code under specific conditions. Its basic syntax is as follows: ifcondition

How to use conditional statements in Java to make logical judgments requires specific code examples. Conditional statements are a commonly used tool in programming, which enable the program to perform different branch executions according to requirements. In Java programs, conditional statements can be used to determine the next action of the program based on the truth or falsehood of a certain condition. This article will introduce the use of conditional statements in Java and give specific code examples. In Java, there are two main forms of conditional statements: if statements and switch statements. if statement if statement is the most commonly used conditional statement

PHP is an open source, general-purpose scripting language that is widely used in the field of web development. In PHP programming, conditional statements are one of the indispensable basic syntaxes, used to implement various logical judgments and flow control in the program. This article will introduce common conditional statements in PHP programming. 1. If statement The most commonly used conditional statement in PHP is the if statement. The syntax of the if statement is as follows: if (conditional expression) {//statement to be executed when the condition is true} where the conditional expression can be anything
