Solved

Could you Explain COALESCE  function in Oracle

Posted on 2011-02-18
3
337 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
Question by:stmani2005
3 Comments
 
LVL 142

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 500 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
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 34928686
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

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 …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This video teaches viewers about errors in exception handling.

746 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

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now