Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Could you Explain COALESCE  function in Oracle

Posted on 2011-02-18
3
Medium Priority
?
367 Views
Last Modified: 2012-05-11
Could you Explain COALESCE function in Oracle


WHERE ACC_LV_CODE_ST like COALESCE(?, ACC_LV_CODE_ST)
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 143

Expert Comment

by:Guy Hengel [angelIII / a3]
ID: 34924783
coalesce will return the first value that is not null.

in your example, if ? (variable, user input ..) is null, it will result in:
WHERE ACC_LV_CODE_ST like ACC_LV_CODE_ST
which means: match all rows

if ? is passed (aka not null), it will be:
WHERE ACC_LV_CODE_ST like ?

 hope this clarifies
0
 
LVL 47

Accepted Solution

by:
for_yan earned 2000 total points
ID: 34927808
This question mark is a bit confusing but in general coalesce() function is rather simple
as they explain in http://www.techonthenet.com/oracle/functions/coalesce.php

SELECT coalesce( address1, address2, address3 ) result
FROM suppliers;

will return:

    IF address1 is not null THEN
         result := address1;

    ELSIF address2 is not null THEN
        result := address2;

    ELSIF address3 is not null THEN
        result := address3;

    ELSE
        result := null;

    END IF;

question mark is a part of the prepared statement as I understand,
if you provide value - it will always become result
if it is given null value then ACC_LV_CODE_ST will become the result


0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question