Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Range of values by item
First of all, it's very good to post create table script, insert
statements and the expected output.
This guarantees more people are willing to look into your problem.
However, when running your scripts, first I got a ".ORA-01401:
inserted value too large for column".
When expanding the "Reader" column to a VARCHAR2(10), the table was
populated, but your query returned:
STA END READER
--- --- ----------
1 1 KFVAN_KIRK 10 10 KFVAN_KIRK 100 109 KFVAN_KIRK
110 119 KFVAN_KIRK 12 12 KFVAN_KIRK 120 129 KFVAN_KIRK 13 13 KFVAN_KIRK 130 139 KFVAN_KIRK 14 14 KFVAN_KIRK 140 149 KFVAN_KIRK 15 15 KFVAN_KIRK 150 159 KFVAN_KIRK 16 16 KFVAN_KIRK 160 169 KFVAN_KIRK 17 17 KFVAN_KIRK 170 179 KFVAN_KIRK 18 18 KFVAN_KIRK 180 189 KFVAN_KIRK 19 19 KFVAN_KIRK 190 199 KFVAN_KIRK 2 2 KFVAN_KIRK
4 4 KFVAN_KIRK 40 49 KFVAN_KIRK 5 5 KFVAN_KIRK 50 59 KFVAN_KIRK 6 6 KFVAN_KIRK 60 69 KFVAN_KIRK 7 7 KFVAN_KIRK 70 79 KFVAN_KIRK 8 8 KFVAN_KIRK 80 89 KFVAN_KIRK 9 9 KFVAN_KIRK 90 99 KFVAN_KIRK
instead of
1 001 100 MWLOVEJOY 2 101 300 KFVAN_KIRK 3 301 330 JWCASHEN
So I just ignored the query and tried to build a new one to give the
desired output.
But again, the output is different from specified. I thought you meant
this:
SQL> select lpad(to_char(min(to_number(specimen_id))),3,'0') "MIN"
2 , lpad(to_char(max(to_number(specimen_id))),3,'0') "MAX" 3 , reader 4 from ( select t.* 5 , max(rn) over (partition by reader order by to_number(specimen_id)) maxrn 6 from ( select reading.* 7 , case lag(to_number(specimen_id)) over (partition by reader order by to_number(specimen_id)) 8 when to_number(specimen_id) - 1 then null 9 else row_number() over (partition by reader order by to_number(specimen_id)) 10 end rn 11 from reading 12 ) t 13 ) 14 group by reader 15 , maxrn 16 order by min 17 , reader
MIN MAX READER
--- --- ----------
001 200 KFVAN_KIRK
001 100 MWLOVEJOY
101 190 JWCASHEN
201 300 MWLOVEJOY
301 330 JWCASHEN
5 rijen zijn geselecteerd.
Finally a tip: if a column is a number, it's best to give it a
datatype number instead of varchar2. This way:
- you don't fool future maintainers of your code
Regards,
Rob.
Received on Tue Jul 03 2007 - 03:21:53 CDT
![]() |
![]() |