Coalesce and coalesce

Source: Internet
Author: User

Coalesce and coalesce

There is such a demand. There are several contacts in the community. If there is a power outage, first notify contact 1. If not, then notify contact 2; otherwise, notify contact 3.

Create table test (
Id number,
Name varchar2 (20 ),
Contact_phone1 varchar2 (20 ),
Contact_phone2 varchar2 (20 ),
Contact_phone3 varchar2 (20 ),
Contact_phone4 varchar2 (20)
);
Insert into test values (1, 'cell 1', '','', '123 ','');
Insert into test values (1, 'cell 2', '', '123 ');
Commit;


SQL> select * from test;
Id name CONTACT_PHONE1 CONTACT_PHONE2 CONTACT_PHONE3 CONTACT_PHONE4
---------------------------------------------------------------------
1 Residential Area 1 13485958522
1 Residential Area 2 13488958536

Without this function, you can first check the data and then use the java code for processing. Coalesce ranges from left to right. In case of the first non-null value, this non-null value is returned, which is determined by multiple layers.

SQL> select id, name, coalesce (contact_phone1,
Contact_phone2,
Contact_phone3,
Contact_phone4) as contact_phone
From test;
Id name CONTACT_PHONE
--------------------------------------------------
1 Residential Area 1 13485958522
1 Residential Area 2 13488958536

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.