当前位置: 代码迷 >> Oracle管理 >> 怎么遍历无规律数据
  详细解决方案

怎么遍历无规律数据

热度:21   发布时间:2016-04-24 05:42:39.0
如何遍历无规律数据
想用循环还遍历一组无规律的数据,如:
for var in ( 45,23,1544,666,48,24) loop 
  --do something
end loop; -----显然这种方法有问题。

我知道可以将这些无规律数据写到一张临时表里,然后select出来,但没有权限建表呢???


请问各位大神,有没有其它方法?



------解决方案--------------------
create or replace type item_tab is table of varchar2(2000)

--is
aaa item_tab ;
cursor c is
select column_value
from table(aaa);

--begin
aaa.extend;
aaa(aaa.count) := 45;
.
.
.

for var in c loop
--do something
end loop;
------解决方案--------------------
不过你没有建表权限,建type的权限也不见得有。
你直接用数组不行吗,循环数组呗,为什么非要select出来?
------解决方案--------------------
SQL code
--Oracle 10g:begin  for var in (        with tab as(      select '45,23,1544,666,48,24' num from dual      )      select regexp_substr(num,'[^,]+',1,level) num from tab      connect by      level<=length(num)-length(replace(num,',',''))+1  )  loop    --do something    dbms_output.put_line(var.num) ;    end loop;end;   PL/SQL block, executed in 0 sec.   45                                 23                                 1544                               666                                48                                 24                                 Total execution time 0.016 sec.
------解决方案--------------------
可以借助oracle的对象类型,建立内部类型
  相关解决方案