1. oracle sql怎么写循环语句
declare
sql_tem Varchar2(4000);
a number;
b number;
i number;
begin
a := 1;
for i in 1 .. 3 loop
b := a + 4;
sql_tem := 'insert into A2 (ID,NAME) (select ID,NAME from A1 WHERE ROWNUM between :1 and :2)';
EXECUTE IMMEDIATE sql_tem
USING a, b;
commit;
a := a + 5;
end loop;
end;
试试上面的代码看一下能不能满意你的要求先呗。
2. 哪位大侠知道怎么写oracle sql 循环语句
循环结构
简单循环【经常使用】:loop……end loop
语法格式:
loop
plsql语句;
[exit when 条件;]
end loop;
说明:exit when 条件,表示当条件成立时退出。
范例:求1~100的和。
declare
i number;
sum1 number;
begin
i:=1;
sum1:=0;
loop
exit when i>100;
sum1:=sum1+i;
i:=i+1;
end loop;
dbms_output.put_line(sum1);
end;
/
范例:向emp表中插入999条记录
declare
i number:=1;
begin
loop
exit when i>999;
insert into emp(empno,ename,deptno) values(i,'jack'||i,40);
dbms_output.put_line('第'||i||'记录已添加');
i:=i+1;
end loop;
end;
/
while循环:while loop……end loop
语法格式
while 条件 loop
plsql语句;
end loop;
例:使用while循环显示1~10
declare
i number;
begin
i:=1;
while i
3. oracle存储过程怎么写循环
Oracle中有三种循环(For、While、Loop):
1、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;
2、while循环:
create or replace procedure pro_test_loop is
i number;
begin
i:=0;
while i
4. 请教大神,oracle数据库循环语句怎么写
假设表中字段分别为:
student 中字段:class_id, student_name,score,pass(number类型)
class中字段:class_id,class_name
select c.class_name,count(*) total ,sum(pass) as pass_count,sum(pass)/count(*) as pass_ratio
from student s,class c
where s.class_id=c.class_id
group by c.class_name
5. SQL 语句简单的循环怎么写啊
**************
修改了一下:
**************
declare @month_tmp varchar(2);
declare @day_tmp varchar(2);
set @month_tmp = '1';
set @day_tmp = '1';
while(@month_tmp < '13')
begin
while(@day_tmp < '30')
begin
select * from table1 where month=@month_tmp and day=@day_tmp
set @day_tmp = @day_tmp + 1
end
set @month_tmp = @month_tmp + 1
set @day_tmp = 1
end
*********************************************************
select * from table1 where
month in('1','2','3','4','5','6','7','8','9','10','11','12'
and
day in('1','2','3','4','5','6','7','8','9','10','11','12','13','14','15','16','17','18','19','20','21','22','23','24','25','26','27','28','29','30');
---
以上,希望对你有所帮助。
转载请注明出处育才学习网 » oracle怎么写循环