Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Could you Explain COALESCE  function in Oracle

Posted on 2011-02-18
3
Medium Priority
?
370 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
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
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:
This video teaches viewers about errors in exception handling.
Suggested Courses

824 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