dbTalk Databases Forums  

DECODE QuestionHi,

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


Discuss DECODE QuestionHi, in the comp.databases.oracle.misc forum.



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

Default DECODE QuestionHi, - 08-22-2008 , 12:47 PM






Hi,

I have a question about DECODE. I know that I can return a 1 or 0
using DECODE:

SELECT (DECODE...,1,0) FROM <table name> WHERE........;

My question is, what you need to just decode the result of the where?
Basically if all the criteria of the WHERE statement is true, return a
1, and if any of the criteria is false, return a 0.

SELECT (DECODE...,1,0) FROM <table name>
WHERE........AND.......AND......;

Is there a way to do that?? Subqueries? Analytical functions??

Reply With Quote
  #2  
Old   
Malcolm Dew-Jones
 
Posts: n/a

Default Re: DECODE QuestionHi, - 08-22-2008 , 06:18 PM






Mtek (mtek (AT) mtekusa (DOT) com) wrote:
: Hi,

: I have a question about DECODE. I know that I can return a 1 or 0
: using DECODE:

: SELECT (DECODE...,1,0) FROM <table name> WHERE........;

: My question is, what you need to just decode the result of the where?
: Basically if all the criteria of the WHERE statement is true, return a
: 1, and if any of the criteria is false, return a 0.

: SELECT (DECODE...,1,0) FROM <table name>
: WHERE........AND.......AND......;

: Is there a way to do that?? Subqueries? Analytical functions??

I am not clear what you mean. Decode can do much more than you describe,
so perhaps your misunderstanding of decode is the issue. Modern Oracle
also has the CASE expression which is often easier than decode.

In your original SQL, the select will return the rows for which the where
is true, so you might get output such as

select 1 from table where XXX;

1
----------
1
1
1
1
1
1
1

7 rows selected.

Is that really the sort of result set that you want? I doubt it.

If you mean to list some data and then flag some of it, perhaps you want
something like

select t.view_name,
case
when view_name like '%X%' then 'LOOKS LIKE X'
else 'not like x'
end
from user_views t;


Reply With Quote
  #3  
Old   
Malcolm Dew-Jones
 
Posts: n/a

Default Re: DECODE QuestionHi, - 08-22-2008 , 06:18 PM



Mtek (mtek (AT) mtekusa (DOT) com) wrote:
: Hi,

: I have a question about DECODE. I know that I can return a 1 or 0
: using DECODE:

: SELECT (DECODE...,1,0) FROM <table name> WHERE........;

: My question is, what you need to just decode the result of the where?
: Basically if all the criteria of the WHERE statement is true, return a
: 1, and if any of the criteria is false, return a 0.

: SELECT (DECODE...,1,0) FROM <table name>
: WHERE........AND.......AND......;

: Is there a way to do that?? Subqueries? Analytical functions??

I am not clear what you mean. Decode can do much more than you describe,
so perhaps your misunderstanding of decode is the issue. Modern Oracle
also has the CASE expression which is often easier than decode.

In your original SQL, the select will return the rows for which the where
is true, so you might get output such as

select 1 from table where XXX;

1
----------
1
1
1
1
1
1
1

7 rows selected.

Is that really the sort of result set that you want? I doubt it.

If you mean to list some data and then flag some of it, perhaps you want
something like

select t.view_name,
case
when view_name like '%X%' then 'LOOKS LIKE X'
else 'not like x'
end
from user_views t;


Reply With Quote
  #4  
Old   
Malcolm Dew-Jones
 
Posts: n/a

Default Re: DECODE QuestionHi, - 08-22-2008 , 06:18 PM



Mtek (mtek (AT) mtekusa (DOT) com) wrote:
: Hi,

: I have a question about DECODE. I know that I can return a 1 or 0
: using DECODE:

: SELECT (DECODE...,1,0) FROM <table name> WHERE........;

: My question is, what you need to just decode the result of the where?
: Basically if all the criteria of the WHERE statement is true, return a
: 1, and if any of the criteria is false, return a 0.

: SELECT (DECODE...,1,0) FROM <table name>
: WHERE........AND.......AND......;

: Is there a way to do that?? Subqueries? Analytical functions??

I am not clear what you mean. Decode can do much more than you describe,
so perhaps your misunderstanding of decode is the issue. Modern Oracle
also has the CASE expression which is often easier than decode.

In your original SQL, the select will return the rows for which the where
is true, so you might get output such as

select 1 from table where XXX;

1
----------
1
1
1
1
1
1
1

7 rows selected.

Is that really the sort of result set that you want? I doubt it.

If you mean to list some data and then flag some of it, perhaps you want
something like

select t.view_name,
case
when view_name like '%X%' then 'LOOKS LIKE X'
else 'not like x'
end
from user_views t;


Reply With Quote
  #5  
Old   
Malcolm Dew-Jones
 
Posts: n/a

Default Re: DECODE QuestionHi, - 08-22-2008 , 06:18 PM



Mtek (mtek (AT) mtekusa (DOT) com) wrote:
: Hi,

: I have a question about DECODE. I know that I can return a 1 or 0
: using DECODE:

: SELECT (DECODE...,1,0) FROM <table name> WHERE........;

: My question is, what you need to just decode the result of the where?
: Basically if all the criteria of the WHERE statement is true, return a
: 1, and if any of the criteria is false, return a 0.

: SELECT (DECODE...,1,0) FROM <table name>
: WHERE........AND.......AND......;

: Is there a way to do that?? Subqueries? Analytical functions??

I am not clear what you mean. Decode can do much more than you describe,
so perhaps your misunderstanding of decode is the issue. Modern Oracle
also has the CASE expression which is often easier than decode.

In your original SQL, the select will return the rows for which the where
is true, so you might get output such as

select 1 from table where XXX;

1
----------
1
1
1
1
1
1
1

7 rows selected.

Is that really the sort of result set that you want? I doubt it.

If you mean to list some data and then flag some of it, perhaps you want
something like

select t.view_name,
case
when view_name like '%X%' then 'LOOKS LIKE X'
else 'not like x'
end
from user_views t;


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.