oracle的循环语句怎么写
- 综合知识
- 关注:2.61W次
create table temp_tab( id number primary key not null, name varchar2(50) not null, age number not null);declare ids number(30) :=0; names varchar2(50) :='卡卡'; age number(30) :=5;begin for i in 1..15 loop ids :=ids+1; age :=age+1; insert into temp_tab values(ids,names,age); end loop;end;。
2. 请问这个oracle的for循环语句怎么写create table temp_tab
(
id number primary key not null,
name varchar2(50) not null,
age number not null
);
declare
ids number(30) :=0;
names varchar2(50) :='卡卡';
age number(30) :=5;
begin
for i in 1..15 loop
ids :=ids+1;
age :=age+1;
insert into temp_tab values(ids,names,age);
end loop;
end;
3. 请教大神,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
4. 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;
试试上面的代码看一下能不能满意你的要求先呗。
5. 哪位大侠知道怎么写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
6. Oracle循环语句的写法有哪些呢如果您对Oracle循环语句方面感兴趣的话,不妨一看。
loop循环: 1。 create or replace procedure pro_test_loop is 2。
i number; 3。 begin 4。
i:=0; 5。 loop 6。
ii:=i+1; 7。 dbms_output。
put_line(i); 8。 if i》5 then 9。
exit; 10。 end if; 11。
end loop; 12。 end pro_test_loop; while循环: 1。
create or replace procedure pro_test_while is 2。 i number; 3。
begin 4。 i:=0; 5。
while i《5 loop 6。 ii:=i+1; 7。
dbms_output。 put_line(i); 8。
end loop; 9。 end pro_test_while; for循环1: 1。
create or replace procedure pro_test_for is 2。 i number; 3。
begin 4。 i:=0; 5。
for i in 1。
5 loop 6。 dbms_output。
put_line(i); 7。 end loop; 8。
end pro_test_for; for循环2: 1。 create or replace procedure pro_test_cursor is 2。
userRow t_user%rowtype; 3。 cursor userRows is 4。
select * from t_user; 5。 begin 6。
for userRow in userRows loop 7。 dbms_output。
put_line(userRow。Id||','||userRow。
Name||','||userRows%rowcount); 8。 end loop; 9。
end pro_test_cursor;。
7. 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');
---
以上,希望对你有所帮助。
- 文章版权属于文章作者所有,转载请注明 https://dongkepu.com/zonghezhishi/8elyve.html