Convert null values to actual values

Source: Internet
Author: User

Convert null values to actual values
Create a test table:

Create or replace view v asselect null as c1, null as c2, '1' AS c3, null as c4, '2' AS c5 FROM dualUNION allselect null as c1, null as c2, null as c3, '3' AS c4, '2' AS c5 FROM dual; SELECT * FROM v;
If you want to query the value of column c3, When Column c3 is empty, it is displayed as 0. There are two methods:
-- Use the nvl function select nvl (c3, '0') c3 FROM v; -- use the coalesce function select coalesce (c3, '0') c3 FROM v;
The query result is as follows: if you want to query the first non-empty value from column c1 to column c5, the following two methods are available:
-- Method 1 select nvl (c1, c2), c3), c4), c5) AS c from v; -- method 2 select coalesce (c1, c2, c3, c4, c5) AS c FROM v;
The query result is as follows: as shown in the following figure, coalesce supports multiple parameters, which can easily return the first non-null value.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.