Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: column length, range of values and ........ decode???

Re: column length, range of values and ........ decode???

From: Martin Burbridge <pobox002_at_bebub.com>
Date: Sat, 25 Jan 2003 02:16:39 GMT
Message-ID: <Xns930DD80335429pobox002bebubcom@204.127.199.17>


mcohen_at_attbi.com (Mike Cohen) wrote in
news:9a742dd3.0301241631.4f284bb_at_posting.google.com:

> I am pulling the length of a comment column: length(t1.d_comment)
>
> Now, I want to group the results, thus if a column is less than 15 in
> length, it goes to group A, if it is between 16 and 49 characters, it
> is in group B, and if it is 50 or greater characters, it goes to group
> C. I then want to count how many rows are in each group. I think
> that using a DECODE and possibly a SIGN are in order, but I don't want
> to have a decode for each possible column length value. Any ideas?

What if it is 15, that doesn't seem to be in your explanation, so I'll assume it's an A. You would just need two decodes to do that.

SQL> var n number
SQL> exec :n := 1

PL/SQL procedure successfully completed.

SQL> select

  2     decode(sign(:n-16),-1,'A',
  3     decode(sign(:n-50),-1,'B',
  4     'C'))

  5 from dual;

D
-
A

SQL> exec :n := 17

PL/SQL procedure successfully completed.

SQL> / D
-
B

SQL> exec :n := 50

PL/SQL procedure successfully completed.

SQL> / D
-
C

SQL> exec :n := 15

PL/SQL procedure successfully completed.

SQL> / D
-
A

To do what you want you to would group by the result shown above and just count.

Hth

Martin Received on Fri Jan 24 2003 - 20:16:39 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US