oracle for循环 计数,ORACLE-FOR循环

循环和过程配合,方便来生成测试数据:

例:

--创建表

create table t_test

(

test_id varchar2(100),

test_name varchar2(100)

);

--查询

select * from t_test;

truncate table t_test;

--声明过程--配合循环插入测试数据

declare

v_index number := 1;

begin

loop

if v_index < 100 then

insert into t_test values ('id'||v_index,'name'||v_index);

v_index := v_index + 1;

else exit;

end if;

end loop;

commit;

end;

-----------------------------------

转自:http://www.cnblogs.com/zheng8145/archive/2008/12/02/1345930.html

loop循环:

create or replace procedure pro_test_loop is

i number;

begin

i:=0;

loop

i:=i+1;

dbms_output.put_line(i);

if i>5 then

exit;

end if;

end loop;

end pro_test_loop;

while循环:

create or replace procedure pro_test_while is

i number;

begin

i:=0;

while i<5 loop

i:=i+1;

dbms_output.put_line(i);

end loop;

end pro_test_while;

for循环1:

create or replace procedure pro_test_for is

i number;

begin

i:=0;

for i in 1..5 loop

dbms_output.put_line(i);

end loop;

end pro_test_for;

for循环2:

create or replace procedure pro_test_cursor is

userRow t_user%rowtype;

cursor userRows is

select * from t_user;

begin

for userRow in userRows loop

dbms_output.put_line(userRow.Id||','||userRow.Name||','||userRows%rowcount);

end loop;

end pro_test_cursor;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值