很简单的层次查询 with t as (select 'a' col1, 1 col2, 3 col3 from dual union all select 'b', 2, 5 from dual union all select 'c', 9, 33 from dual) select distinct col1, col2 + level - 1 from t connect by level <= col3 - col2 + 1 order by col1;
我擦,我怎么看不懂,connect by?
看不懂?不是搞oracle开发的?
看不懂?不是搞oracle开发的?没学过这种查询。。刚查了下不太明白
declare cursor cur_a is select * from A; begin for a_row in cur_a loop for i in a_row.col2..a_row.col3 loop dbms_output.put_line(a_row.col1||' '||i); end loop; end loop; end;用游标cur_a获取表A中的数据,二层for循环,外层遍历游标,内层遍历该行数据
with t as
(select 'a' col1, 1 col2, 3 col3
from dual
union all
select 'b', 2, 5
from dual
union all
select 'c', 9, 33 from dual)
select distinct col1, col2 + level - 1
from t
connect by level <= col3 - col2 + 1
order by col1;
看不懂?不是搞oracle开发的?
看不懂?不是搞oracle开发的?没学过这种查询。。刚查了下不太明白
declare
cursor cur_a is select * from A;
begin
for a_row in cur_a loop
for i in a_row.col2..a_row.col3 loop
dbms_output.put_line(a_row.col1||' '||i);
end loop;
end loop;
end;用游标cur_a获取表A中的数据,二层for循环,外层遍历游标,内层遍历该行数据