SQL 语句简单的循环怎么写啊!

来源:百度知道 编辑:UC知道 时间:2024/06/23 15:47:25
各位大哥,我是新手,SQL的简单循环写不出来了,手工执行太累啦
select * from table1 where month='1' and day='1'
我想month在1-12里循环,day在1-31里循环,怎么才能写出来一个SQL啊,帮帮我吧,兄弟们!
我用的是ORACLE,还可能实现这样的循环不?

**************
修改了一下:
**************
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'