dbTalk Databases Forums  

Choose one of two values

comp.databases.oracle.misc comp.databases.oracle.misc


Discuss Choose one of two values in the comp.databases.oracle.misc forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Sashi
 
Posts: n/a

Default Choose one of two values - 09-28-2009 , 09:40 AM






Hi all,

I'm running a simple select stmt thus:

select A.value, b.value
from A, B
where ...

However, either A.value or B.value is null and I need to select the
non null value.
Is there a way of specifying within pl/sql this construct?

Pseudocode:

Select ( if (A.value) is null and (B.value) is not null then B.value
else
if (B.value) is null and (A.value) is not null then
A.value
else
if (B.value) is not null and (A.value) is not null then
A.value)
From A, B
where ...

In the third case above, either is ok so I arbitrarily cose A.value.

Hope this is clean enough.

Thanks in advance,
Sashi

Reply With Quote
  #2  
Old   
Sashi
 
Posts: n/a

Default Re: Choose one of two values - 09-28-2009 , 09:56 AM






On Sep 28, 10:40*am, Sashi <small... (AT) gmail (DOT) com> wrote:
Quote:
Hi all,

I'm running a simple select stmt thus:

select A.value, b.value
from A, B
where ...

However, either A.value or B.value is null and I need to select the
non null value.
Is there a way of specifying within pl/sql this construct?

Pseudocode:

Select ( if (A.value) is null and (B.value) is not null then B.value
* * * * * * else
* * * * * * if (B.value) is null and (A.value) is not null then
A.value
* * * * * * else
* * * * * * if (B.value) is not null and (A.value) is not null then
A.value)
From A, B
where ...

In the third case above, either is ok so I arbitrarily cose A.value.

Hope this is clean enough.

Thanks in advance,
Sashi
Well, I found this nifty string function that seems to do what I need:

select coalesce(A.value, B.value)
from A, B
where ...

If there's any caveats or any other reason that I shouldn't use this,
please let me know.
Also any other alternatives that work are appreciated as well.
TIMTOWTDI works in all areas for me.

Thanks,
Sashi

Reply With Quote
  #3  
Old   
Mark D Powell
 
Posts: n/a

Default Re: Choose one of two values - 09-28-2009 , 01:22 PM



On Sep 28, 10:56*am, Sashi <small... (AT) gmail (DOT) com> wrote:
Quote:
On Sep 28, 10:40*am, Sashi <small... (AT) gmail (DOT) com> wrote:





Hi all,

I'm running a simple select stmt thus:

select A.value, b.value
from A, B
where ...

However, either A.value or B.value is null and I need to select the
non null value.
Is there a way of specifying within pl/sql this construct?

Pseudocode:

Select ( if (A.value) is null and (B.value) is not null then B.value
* * * * * * else
* * * * * * if (B.value) is null and (A.value) is not null then
A.value
* * * * * * else
* * * * * * if (B.value) is not null and (A.value) is not null then
A.value)
From A, B
where ...

In the third case above, either is ok so I arbitrarily cose A.value.

Hope this is clean enough.

Thanks in advance,
Sashi

Well, I found this nifty string function that seems to do what I need:

select coalesce(A.value, B.value)
from A, B
where ...

If there's any caveats or any other reason that I shouldn't use this,
please let me know.
Also any other alternatives that work are appreciated as well.
TIMTOWTDI works in all areas for me.

Thanks,
Sashi- Hide quoted text -

- Show quoted text -
The coalesce function is an ANSI/ISO standard function of the SQL
lanaguage to return the first non-null value encountered in a list.
Being part of the SQL standard I would recommend its use.

HTH -- Mark D Powell --

Reply With Quote
  #4  
Old   
Sashi
 
Posts: n/a

Default Re: Choose one of two values - 09-28-2009 , 10:03 PM



On Sep 28, 2:22*pm, Mark D Powell <Mark.Powe... (AT) hp (DOT) com> wrote:
Quote:
On Sep 28, 10:56*am, Sashi <small... (AT) gmail (DOT) com> wrote:



On Sep 28, 10:40*am, Sashi <small... (AT) gmail (DOT) com> wrote:

Hi all,

I'm running a simple select stmt thus:

select A.value, b.value
from A, B
where ...

However, either A.value or B.value is null and I need to select the
non null value.
Is there a way of specifying within pl/sql this construct?

Pseudocode:

Select ( if (A.value) is null and (B.value) is not null then B.value
* * * * * * else
* * * * * * if (B.value) is null and (A.value) is not null then
A.value
* * * * * * else
* * * * * * if (B.value) is not null and (A.value) is notnull then
A.value)
From A, B
where ...

In the third case above, either is ok so I arbitrarily cose A.value.

Hope this is clean enough.

Thanks in advance,
Sashi

Well, I found this nifty string function that seems to do what I need:

select coalesce(A.value, B.value)
from A, B
where ...

If there's any caveats or any other reason that I shouldn't use this,
please let me know.
Also any other alternatives that work are appreciated as well.
TIMTOWTDI works in all areas for me.

Thanks,
Sashi- Hide quoted text -

- Show quoted text -

The coalesce function is an ANSI/ISO standard function of the SQL
lanaguage to return the first non-null value encountered in a list.
Being part of the SQL standard I would recommend its use.

HTH -- Mark D Powell --
Wasn't that serendipitous!
I was checking out the string functions on psoug.org and accidentally
discovered this function.
Thanks for your input, Mark.
Regards,
Sashi

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.