oracle 之 for循环表

 

代码

create table tm_lzh as
SELECT 'a1' c1,'b1' c2 FROM dual
union all
SELECT 'a2' c1,'b2' c2 FROM dual
union all
SELECT 'a3' c1,'b3' c2 FROM dual
union all
SELECT 'a4' c1,'b4' c2 FROM dual
union all
SELECT 'a5' c1,'b5' c2 FROM dual
union all
SELECT 'a6' c1,'b6' c2 FROM dual;

DECLARE
a varchar2(10);
b varchar2(10);
begin
for i in(select c1,c2 from tm_lzh) loop
    a:=i.c1;
    b:=i.c2;
    dbms_output.put_line('i.c1='||i.c1);
    dbms_output.put_line('i.c2='||i.c2);
    dbms_output.put_line('a='||a);
    dbms_output.put_line('b='||b);
  end loop;
end;

执行结果

 

posted on 2021-07-20 17:39  Simple-Sir  阅读(1071)  评论(0编辑  收藏  举报

导航