0
with bar_no as (
select 1 start_bar, 5 end_bar from dual)
select barcode
from (select level barcode
from dual
connect by level <= (select max(end_bar) from bar_no)) a
where exists (
select 1
from bar_no
where barcode between bar_no.start_bar and bar_no.end_bar)

这将返回: 1 2 3 4 5

我需要一些帮助来推进这个查询。如何将查询设置为多次打印每个数字(返回)。

例如:

打印 1 到 5 之间的数字并打印每个数字 3 次。

最终结果:1 1 1 2 2 2 3 3 3 4 4 4 5 5 5

顺便提一句。我将在 Jasper ireport 中使用它并且不想使用 procs 、 function 等

请帮忙!提前致谢

4

2 回答 2

3

您可以在语句中生成序列,with然后将它们连接在一起:

with bar_no as (
      select 1 start_bar, 5 end_bar from dual
     ),
     codes as (
      select level + start_bar - 1 start_bar
      from bar_no
           connect by level <= end_bar - start_bar + 1
     ),
     counts as (
       select level as repcnt
       from dual connect by level <= 3
     )
select *
from codes cross join counts
order by 1, 2;
于 2013-07-29T13:16:37.713 回答
0

尝试使用如下所示的 corss join

with bar_no as (
select 1 start_bar, 5 end_bar from dual)
select barcode
from (select level barcode
from dual
connect by level <= (select max(end_bar) from bar_no)) a
where exists (
select 1
from bar_no
cross join 
(
  select 1
  union all
  select 2
  union all
  select 3  
   ) CJ
where barcode between bar_no.start_bar and bar_no.end_bar)
于 2013-07-29T13:11:51.920 回答