oracle的迴圈語句怎麼寫
- 綜合知識
- 關注:2.38W次
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://shqsg.com/zonghezhishi/rzmoqz.html