Solved

Could you Explain COALESCE  function in Oracle

Posted on 2011-02-18
3
344 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
mapAB Challlenge 35 128
Starting to learn JAVA, 7 60
difference of if loops 23 43
tomcat administrtor 12 34
For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
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 regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

863 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

18 Experts available now in Live!

Get 1:1 Help Now