dbTalk Databases Forums  

Use default value when no rows returns.

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


Discuss Use default value when no rows returns. in the comp.databases.oracle.misc forum.



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

Default Use default value when no rows returns. - 10-23-2008 , 05:55 AM






Hi All,

I need a help.

I have a query inside one shell script and i'm wondering how to return
any default value when no rows return from my query.

For example:

printf "%s\n" "set pages 0" "set feed off"
"SELECT value FROM tableA WHERE date > to_date('01/11/2010','dd/mm/
yyyy') ;"
Quote:
sqlplus -s user/password | while read nr3
from my query "SELECT value FROM tableA WHERE date >
to_date('01/11/2010','dd/mm/yyyy') ;" no value is returned and when no
row return i would like to assign a default value like '-1 ' for
example.

value
--------
-1

Thanks in advance!!


Reply With Quote
  #2  
Old   
Ed Prochak
 
Posts: n/a

Default Re: Use default value when no rows returns. - 10-23-2008 , 08:18 AM






On Oct 23, 5:55*am, Beto <andred... (AT) hotmail (DOT) com> wrote:
Quote:
Hi All,

I need a help.

I have a query inside one shell script and i'm wondering how to return
any default value when no rows return from my query.

For example:

printf "%s\n" "set pages 0" "set feed off"
"SELECT value FROM tableA WHERE date > to_date('01/11/2010','dd/mm/
yyyy') ;"
| sqlplus -s user/password | while read nr3

from my query "SELECT value FROM tableA WHERE date
to_date('01/11/2010','dd/mm/yyyy') ;" no value is returned and when no
row return i would like to assign a default value like '-1 ' for
example.

value
--------
*-1

Thanks in advance!!
The only solution I can think of is some aggregate function. For
example
select nvl(max(value),-1) FROM tableA
WHERE date > to_date('01/11/2010','dd/mm/yyyy') ;
guarantees one row. Would using some aggregate function work for you?

Ed


Reply With Quote
  #3  
Old   
Ed Prochak
 
Posts: n/a

Default Re: Use default value when no rows returns. - 10-23-2008 , 08:18 AM



On Oct 23, 5:55*am, Beto <andred... (AT) hotmail (DOT) com> wrote:
Quote:
Hi All,

I need a help.

I have a query inside one shell script and i'm wondering how to return
any default value when no rows return from my query.

For example:

printf "%s\n" "set pages 0" "set feed off"
"SELECT value FROM tableA WHERE date > to_date('01/11/2010','dd/mm/
yyyy') ;"
| sqlplus -s user/password | while read nr3

from my query "SELECT value FROM tableA WHERE date
to_date('01/11/2010','dd/mm/yyyy') ;" no value is returned and when no
row return i would like to assign a default value like '-1 ' for
example.

value
--------
*-1

Thanks in advance!!
The only solution I can think of is some aggregate function. For
example
select nvl(max(value),-1) FROM tableA
WHERE date > to_date('01/11/2010','dd/mm/yyyy') ;
guarantees one row. Would using some aggregate function work for you?

Ed


Reply With Quote
  #4  
Old   
Ed Prochak
 
Posts: n/a

Default Re: Use default value when no rows returns. - 10-23-2008 , 08:18 AM



On Oct 23, 5:55*am, Beto <andred... (AT) hotmail (DOT) com> wrote:
Quote:
Hi All,

I need a help.

I have a query inside one shell script and i'm wondering how to return
any default value when no rows return from my query.

For example:

printf "%s\n" "set pages 0" "set feed off"
"SELECT value FROM tableA WHERE date > to_date('01/11/2010','dd/mm/
yyyy') ;"
| sqlplus -s user/password | while read nr3

from my query "SELECT value FROM tableA WHERE date
to_date('01/11/2010','dd/mm/yyyy') ;" no value is returned and when no
row return i would like to assign a default value like '-1 ' for
example.

value
--------
*-1

Thanks in advance!!
The only solution I can think of is some aggregate function. For
example
select nvl(max(value),-1) FROM tableA
WHERE date > to_date('01/11/2010','dd/mm/yyyy') ;
guarantees one row. Would using some aggregate function work for you?

Ed


Reply With Quote
  #5  
Old   
Ed Prochak
 
Posts: n/a

Default Re: Use default value when no rows returns. - 10-23-2008 , 08:18 AM



On Oct 23, 5:55*am, Beto <andred... (AT) hotmail (DOT) com> wrote:
Quote:
Hi All,

I need a help.

I have a query inside one shell script and i'm wondering how to return
any default value when no rows return from my query.

For example:

printf "%s\n" "set pages 0" "set feed off"
"SELECT value FROM tableA WHERE date > to_date('01/11/2010','dd/mm/
yyyy') ;"
| sqlplus -s user/password | while read nr3

from my query "SELECT value FROM tableA WHERE date
to_date('01/11/2010','dd/mm/yyyy') ;" no value is returned and when no
row return i would like to assign a default value like '-1 ' for
example.

value
--------
*-1

Thanks in advance!!
The only solution I can think of is some aggregate function. For
example
select nvl(max(value),-1) FROM tableA
WHERE date > to_date('01/11/2010','dd/mm/yyyy') ;
guarantees one row. Would using some aggregate function work for you?

Ed


Reply With Quote
  #6  
Old   
Aya the Vampire Slayer
 
Posts: n/a

Default Re: Use default value when no rows returns. - 10-23-2008 , 11:51 AM



Beto <andredigi (AT) hotmail (DOT) com> wa:
Quote:
I have a query inside one shell script and i'm wondering how to return
any default value when no rows return from my query.

For example:

printf "%s\n" "set pages 0" "set feed off"
"SELECT value FROM tableA WHERE date > to_date('01/11/2010','dd/mm/
yyyy') ;"
| sqlplus -s user/password | while read nr3

from my query "SELECT value FROM tableA WHERE date
to_date('01/11/2010','dd/mm/yyyy') ;" no value is returned and when no
row return i would like to assign a default value like '-1 ' for
example.

value
--------
-1
This should work assuming you really are only selecting one column in
the case where rows are actually returned. However, it does include a
UNION and a subquery.

SELECT value FROM tableA WHERE date > (...)
UNION
SELECT '-1' FROM dual WHERE (SELECT count(*) FROM tableA WHERE date > (...))=0;

It may be more efficient to catch the lack of rows returned in the shell
script somehow rather than trying to do it from the select, in this case.


--
"Care must be exorcised when handring Opiticar System as it is apts to
be sticked by dusts and hand-fat." --Japanese Translators

"Keep your fingers off the lens." --Elton Byington, English Translator


Reply With Quote
  #7  
Old   
Aya the Vampire Slayer
 
Posts: n/a

Default Re: Use default value when no rows returns. - 10-23-2008 , 11:51 AM



Beto <andredigi (AT) hotmail (DOT) com> wa:
Quote:
I have a query inside one shell script and i'm wondering how to return
any default value when no rows return from my query.

For example:

printf "%s\n" "set pages 0" "set feed off"
"SELECT value FROM tableA WHERE date > to_date('01/11/2010','dd/mm/
yyyy') ;"
| sqlplus -s user/password | while read nr3

from my query "SELECT value FROM tableA WHERE date
to_date('01/11/2010','dd/mm/yyyy') ;" no value is returned and when no
row return i would like to assign a default value like '-1 ' for
example.

value
--------
-1
This should work assuming you really are only selecting one column in
the case where rows are actually returned. However, it does include a
UNION and a subquery.

SELECT value FROM tableA WHERE date > (...)
UNION
SELECT '-1' FROM dual WHERE (SELECT count(*) FROM tableA WHERE date > (...))=0;

It may be more efficient to catch the lack of rows returned in the shell
script somehow rather than trying to do it from the select, in this case.


--
"Care must be exorcised when handring Opiticar System as it is apts to
be sticked by dusts and hand-fat." --Japanese Translators

"Keep your fingers off the lens." --Elton Byington, English Translator


Reply With Quote
  #8  
Old   
Aya the Vampire Slayer
 
Posts: n/a

Default Re: Use default value when no rows returns. - 10-23-2008 , 11:51 AM



Beto <andredigi (AT) hotmail (DOT) com> wa:
Quote:
I have a query inside one shell script and i'm wondering how to return
any default value when no rows return from my query.

For example:

printf "%s\n" "set pages 0" "set feed off"
"SELECT value FROM tableA WHERE date > to_date('01/11/2010','dd/mm/
yyyy') ;"
| sqlplus -s user/password | while read nr3

from my query "SELECT value FROM tableA WHERE date
to_date('01/11/2010','dd/mm/yyyy') ;" no value is returned and when no
row return i would like to assign a default value like '-1 ' for
example.

value
--------
-1
This should work assuming you really are only selecting one column in
the case where rows are actually returned. However, it does include a
UNION and a subquery.

SELECT value FROM tableA WHERE date > (...)
UNION
SELECT '-1' FROM dual WHERE (SELECT count(*) FROM tableA WHERE date > (...))=0;

It may be more efficient to catch the lack of rows returned in the shell
script somehow rather than trying to do it from the select, in this case.


--
"Care must be exorcised when handring Opiticar System as it is apts to
be sticked by dusts and hand-fat." --Japanese Translators

"Keep your fingers off the lens." --Elton Byington, English Translator


Reply With Quote
  #9  
Old   
Aya the Vampire Slayer
 
Posts: n/a

Default Re: Use default value when no rows returns. - 10-23-2008 , 11:51 AM



Beto <andredigi (AT) hotmail (DOT) com> wa:
Quote:
I have a query inside one shell script and i'm wondering how to return
any default value when no rows return from my query.

For example:

printf "%s\n" "set pages 0" "set feed off"
"SELECT value FROM tableA WHERE date > to_date('01/11/2010','dd/mm/
yyyy') ;"
| sqlplus -s user/password | while read nr3

from my query "SELECT value FROM tableA WHERE date
to_date('01/11/2010','dd/mm/yyyy') ;" no value is returned and when no
row return i would like to assign a default value like '-1 ' for
example.

value
--------
-1
This should work assuming you really are only selecting one column in
the case where rows are actually returned. However, it does include a
UNION and a subquery.

SELECT value FROM tableA WHERE date > (...)
UNION
SELECT '-1' FROM dual WHERE (SELECT count(*) FROM tableA WHERE date > (...))=0;

It may be more efficient to catch the lack of rows returned in the shell
script somehow rather than trying to do it from the select, in this case.


--
"Care must be exorcised when handring Opiticar System as it is apts to
be sticked by dusts and hand-fat." --Japanese Translators

"Keep your fingers off the lens." --Elton Byington, English Translator


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.