dbTalk Databases Forums  

Strange behavior in GROUP BY

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


Discuss Strange behavior in GROUP BY in the comp.databases.oracle.misc forum.



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

Default Strange behavior in GROUP BY - 11-29-2007 , 09:03 AM






Hi all,

the following query attempts to produce the total salary per the
number of 'A's in employee name (scott/tiger) and it works.

select length(ename)-length(replace(ename,'A','')), sum(sal)
from emp
group by length(ename)-length(replace(ename,'A',''));

The next query tries to beautify output and it does not:

select 'number of A is ' || length(ename)-
length(replace(ename,'A','')), sum(sal)
from emp
group by 'number of A is ' || length(ename)-
length(replace(ename,'A',''));

I get an unexpected (for me) error, which I cannot figure out:

group by 'number of A is ' || length(ename)-
length(replace(ename,'A',''))
*
ERROR at line 3:
ORA-01722: invalid number

(asterisk appears below the second bar of concat operator ||)

Something wrong with concatenation in GROUP BY? Something else?

TIA
Kostis Vezerides

Reply With Quote
  #2  
Old   
fitzjarrell@cox.net
 
Posts: n/a

Default Re: Strange behavior in GROUP BY - 11-29-2007 , 09:40 AM






On Nov 29, 9:03 am, vezerid <veze... (AT) act (DOT) edu> wrote:
Quote:
Hi all,

the following query attempts to produce the total salary per the
number of 'A's in employee name (scott/tiger) and it works.

select length(ename)-length(replace(ename,'A','')), sum(sal)
from emp
group by length(ename)-length(replace(ename,'A',''));

The next query tries to beautify output and it does not:

select 'number of A is ' || length(ename)-
length(replace(ename,'A','')), sum(sal)
from emp
group by 'number of A is ' || length(ename)-
length(replace(ename,'A',''));

I get an unexpected (for me) error, which I cannot figure out:

group by 'number of A is ' || length(ename)-
length(replace(ename,'A',''))
*
ERROR at line 3:
ORA-01722: invalid number

(asterisk appears below the second bar of concat operator ||)

Something wrong with concatenation in GROUP BY? Something else?

TIA
Kostis Vezerides
It's your 'formula' that's suspect. It should be:

select 'number of A is ' || (length(ename) -
length(replace(ename,'A',''))), sum(sal)
from emp
group by 'number of A is ' || (length(ename) -
length(replace(ename,'A','')));


'NUMBEROFAIS'||(LENGTH(ENAME)-LENGTH(REPLACE(ENAME,'A', SUM(SAL)
------------------------------------------------------- ----------
number of A is 1 10350
number of A is 0 17575
number of A is 2 1100



David Fitzjarrell


Reply With Quote
  #3  
Old   
vezerid
 
Posts: n/a

Default Re: Strange behavior in GROUP BY - 11-29-2007 , 10:24 AM



Thanks David. I can't believe I messed up the paste so bad...

Kostis

On Nov 29, 5:40 pm, "fitzjarr... (AT) cox (DOT) net" <fitzjarr... (AT) cox (DOT) net> wrote:
Quote:
On Nov 29, 9:03 am, vezerid <veze... (AT) act (DOT) edu> wrote:



Hi all,

the following query attempts to produce the total salary per the
number of 'A's in employee name (scott/tiger) and it works.

select length(ename)-length(replace(ename,'A','')), sum(sal)
from emp
group by length(ename)-length(replace(ename,'A',''));

The next query tries to beautify output and it does not:

select 'number of A is ' || length(ename)-
length(replace(ename,'A','')), sum(sal)
from emp
group by 'number of A is ' || length(ename)-
length(replace(ename,'A',''));

I get an unexpected (for me) error, which I cannot figure out:

group by 'number of A is ' || length(ename)-
length(replace(ename,'A',''))
*
ERROR at line 3:
ORA-01722: invalid number

(asterisk appears below the second bar of concat operator ||)

Something wrong with concatenation in GROUP BY? Something else?

TIA
Kostis Vezerides

It's your 'formula' that's suspect. It should be:

select 'number of A is ' || (length(ename) -
length(replace(ename,'A',''))), sum(sal)
from emp
group by 'number of A is ' || (length(ename) -
length(replace(ename,'A','')));

'NUMBEROFAIS'||(LENGTH(ENAME)-LENGTH(REPLACE(ENAME,'A', SUM(SAL)
------------------------------------------------------- ----------
number of A is 1 10350
number of A is 0 17575
number of A is 2 1100

David Fitzjarrell


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.