Home Database Mysql Tutorial [每日一题] OCP1z0-047 :2013-08-29 NULL_MySQL

[每日一题] OCP1z0-047 :2013-08-29 NULL_MySQL

Jun 01, 2016 pm 01:30 PM
expression Universal

bitsCN.com

[每日一题] OCP1z0-047 :2013-08-29 NULL

 

[每日一题] OCP1z0-047 :2013-08-29 NULL_MySQL

 

正确答案:B

 

 

用函数可以针对各种数据类型时行操作,包括NULL值在内。其中有一类通用函数,是专门针对NULL值的。

 

 

1、针对NULL值的通用函数

(1)NVL(表达式1,表达式2): 转换空值为一个实际值。如果表达式1值为空,NVL将返回表达式2的值作为结果。如果表达式1

 

 

不为空,以表达式1的值作为结果。

 这个函数在有些时候非常有用,在很多应用程序中,都要把空当作0处理,这利用NVL是容易实现的:

[html] gyj@OCM> select name,salary,nvl(salary,0) from t1;  NAME           SALARY NVL(SALARY,0)  ---------- ---------- -------------  gyj2             8000          8000  gyj3            10000         10000  gyj4            15000         15000  gyj8                     0  
Copy after login

2)NVL2 (表达式1,表达式2,表达式3)

此函数比NVL更复杂些。它首先判断表达式1的值,如果表达式1非空,函数返回表达式2的值作为结果。如果表达式1 为空, 返回

表达式3的值为结果。表达式1 可以是任意数据类型、运算式子。

仍以上面的例子为准,将SAL列中为空的转换成0,不为空的不变:

[html] gyj@OCM> select name,salary,nvl2(salary,salary,0) from t1;  NAME           SALARY NVL2(SALARY,SALARY,0)  ---------- ---------- ---------------------  gyj2             8000                  8000  gyj3            10000                 10000  gyj4            15000                 15000  gyj8                                      0  
Copy after login

(3)NULLIF(表达式1,表达式2)

比较两个表达式,如果相等返回空;如果不相等,返回第一个表达式。

用它可以实现和上面例子中相反的效果。有些应用程序,要求把为0的值显示为空:

[html] gyj@OCM> update t1 set salary=0 where id=5;  1 row updated.  gyj@OCM> commit;  Commit complete.  gyj@OCM> select id,name,nullif(salary,0) from t1;          ID NAME       NULLIF(SALARY,0)  ---------- ---------- ----------------           2 gyj2                   8000           3 gyj3                  10000           4 gyj4                  15000           5 gyj5           7 gyj7                  12000  
Copy after login

nullif(sal,0),就是将SAL为0的转变为空。NVL和NVL2是将为空的转变成其他不是空的值。

(4)COALESCE(表达式1,表达式2,表达式3,…………,表达式n)

返回表达式列表中的第一个值为非空的表达式的值。

它可以实现和NVL一样的功能,而且它的功能比NVL强。如果用它来实现将NULL转为0的操作,方法如下:

[html] gyj@OCM> select id,name,COALESCE(salary,0) from t1;     ID NAME       COALESCE(SALARY,0)  ---------- ---------- ------------------           2 gyj2                     8000           3 gyj3                    10000           4 gyj4                    15000           5 gyj5                        0           7 gyj7                    12000  
Copy after login

 


bitsCN.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Article

Roblox: Bubble Gum Simulator Infinity - How To Get And Use Royal Keys
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Nordhold: Fusion System, Explained
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Mandragora: Whispers Of The Witch Tree - How To Unlock The Grappling Hook
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

Java Tutorial
1665
14
PHP Tutorial
1269
29
C# Tutorial
1249
24
How to Download Drivers for Universal PnP Monitors: 5 Ways How to Download Drivers for Universal PnP Monitors: 5 Ways Apr 21, 2023 pm 08:55 PM

If you have recently upgraded to Windows 10 or Windows 11, you may need to download a universal PnP monitor driver on your PC. Therefore, we have come up with a tutorial that will tell you more about Universal PnP Monitor and some quick ways to download and install Universal PnP Drivers on Windows. You may need to download drivers for most monitor brands, including the AcerGenericPnP monitor driver. When looking for monitor types in Device Manager or under the Monitors tab of the display adapter properties, you may notice Generic PnP Monitor. Chances are you'll find it in dual-monitor setups on both laptops and desktops. Down

How to disable universal watermark on Windows 11 PCs and laptops? How to disable universal watermark on Windows 11 PCs and laptops? Apr 21, 2023 pm 02:49 PM

Are you bothered by the annoying watermark in the lower right corner of your Windows 11 screen? You don't know how to delete it? Universal WatermarkDisabler for Windows 11 is a tool that can help remove the annoying watermark in the lower right corner of the Windows screen that interferes with wallpapers and the overall experience. Without further ado, let’s get started. 3 Solutions to Remove Watermark from Windows 11 1. Use Universal Watermark Disabler to Remove Watermark The easiest way to remove evaluation copy watermark in Windows 11 is to use Universal Watermark Disabler, which is a third-party free software

Looking forward to the Detroit Auto Show: Ford, GM and Stellantis will participate in the exhibition with their brands Looking forward to the Detroit Auto Show: Ford, GM and Stellantis will participate in the exhibition with their brands Jun 09, 2023 pm 09:15 PM

According to news on June 8, the organizers of the Detroit Auto Show recently announced that this year’s Detroit Auto Show will officially open on September 13. It is reported that the organizers promised that this year's auto show will be more exciting than last year and attract more participating brands and car companies to participate. Although the specific number of participating car companies has not yet been disclosed, according to the editor, the number of participating brands is expected to double compared with last year. This will make this year's Detroit Auto Show even more attractive and influential. Affected by the epidemic last year, many car manufacturers decided not to participate in the show, including Honda, Hyundai, Kia, Nissan, as well as brands such as Audi, Porsche and Jaguar Land Rover. However, things will be different this year. Automobile giants such as Ford, General Motors and Stellantis will participate in this session

How to get universal controls on Mac and iPad right now with beta How to get universal controls on Mac and iPad right now with beta Jul 07, 2023 pm 09:49 PM

Requirements In addition to running macOS Monterey 12.3 or newer and iPadOS 15.4 or newer, you'll also need a newer Mac (any 2016 or newer MacBook Pro, or 2018 or newer MacBook Air, Mini, or iMac, or Mac Pro), and newer iPad (any iPad Pro, iPad Air 3rd generation or later, iPad 6th generation or later, iPad Mini 5th generation or later). Any device that wants to use Universal Control needs to be logged into the same Apple ID account that has iCloud enabled. Pass Beta now on M

Microsoft Teams is optimized for Apple Silicon as a 'Universal App' and is now available in beta Microsoft Teams is optimized for Apple Silicon as a 'Universal App' and is now available in beta Apr 15, 2023 am 08:40 AM

Microsoft Teams has finally received a version that interacts directly with ARM-based chipsets in the latest Mac PCs. A beta version of Teams optimized for Apple Silicon is available directly from Microsoft. About a year and a half ago, Apple released Mac PCs with its own proprietary chipset. Designed by Apple engineers, the M1 SoC has received a lot of praise. While the previous generation of Apple PCs featured Intel processors, these are based on ARM

How to solve Python expression syntax errors? How to solve Python expression syntax errors? Jun 24, 2023 pm 05:04 PM

Python, as a high-level programming language, is easy to learn and use. Once you need to write a Python program, you will inevitably encounter syntax errors, and expression syntax errors are a common one. In this article, we will discuss how to resolve expression syntax errors in Python. Expression syntax errors are one of the most common errors in Python, and they are usually caused by incorrect usage of syntax or missing necessary components. In Python, expressions usually consist of numbers, strings, variables, and operators. most common

Java Lambda Expression in Practice: Unlocking the Mysteries of Functional Programming with Code Java Lambda Expression in Practice: Unlocking the Mysteries of Functional Programming with Code Feb 26, 2024 am 10:25 AM

Lambda expression, as the name suggests, is an anonymous function with the arrow symbol (->) as its core. It allows you to pass blocks of code as arguments to other methods, or store them into variables for later use. Lambda expression syntax is concise and easy to understand, and it is very suitable for processing data flow and parallel computing. 1. The basic syntax of Lambda expression The basic syntax of Lambda expression is as follows: (parameter list)->{code block} Among them, the parameter list and code block are optional. If there is only one parameter, the parentheses can be omitted. If the code block is only one line, the curly braces can be omitted. For example, the following code block uses a Lambda expression to add 1 to a number: List

In C and C++, comma is used to separate expressions or statements In C and C++, comma is used to separate expressions or statements Sep 09, 2023 pm 05:33 PM

In C or C++, the comma "," has different uses. Here we will learn how to use them. Commas as operators. The comma operator is a binary operator that evaluates the first operand, discards the result, then evaluates the second operand and returns the value. The comma operator has the lowest precedence in C or C++. Example #include<stdio.h>intmain(){ intx=(50,60); inty=(func1(),func2());} Here 60 will be assigned to x. For the next statement, func1( will be executed first

See all articles