zdly.net
当前位置:首页 >> 哪位大侠知道怎么写orAClE sql 循环语句 >>

哪位大侠知道怎么写orAClE sql 循环语句

循环结构简单循环【经常使用】:loop……end loop语法格式:loopplsql语句;[exit when 条件;]end loop;说明:exit when 条件,表示当条件成立时退出.范例:求1~100的和.declarei number;sum1 number;begini:=1;sum1:=0;loopexit when i>

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; 试试上面的代码看一下能不能满意你的要求先呗

只能 select * from dd_20140101 union all select * from dd_20140102 .. 这种了. 你简单点,也只能对日期进行循环,然后拼SQL语句.变成字符串再执行.

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;

用CURSOR,然后用EXECUTE IMMEDIATE '*****' 即可

tsql(就是sqlserver的),亲测成功:-----------------------------------declare @res varchar(100)declare @c varchar(10)set @res=''declare c1 cursor for select B from topen c1fetch next from c1 into @cwhile @@fetch_status=0begin set @res=@res+@c fetch next from c1 into @cendclose c1deallocate c1select @res

begin CURSOR atemp ISselect A1 from a ;for astemp in atemp loopselect count(*) as num from b where b.b1=astemp.a1;if num=0 thenvSQL :='insert into B select * from a where a.A1=&#

select t.sid,t.hobby from (select row_number() over (partition by sid order by hobby desc ) as num,sid,hobby from info) t where t.num <= 4;

ORACLE循环语句 1、 Exit When 循环: www.2cto.com Sql代码 declare -- Local variables here i integer; begin i:=0; LOOP Exit When(i>5); Dbms_Output.put_line(i); i:=i+1; END LOOP; end; 2、 Loop 循环 Java代码 declare -- Local variables here i

咦,刚有回答你一个问题.你这个是只判断table1.number>table2.number情况下才update.其他情况不考虑.update table1 t3 set t3.number = (select number from (select t1.id, t1.number - t2.number number from table1 t1, table2 t2 where t1.id = t2

网站首页 | 网站地图
All rights reserved Powered by www.zdly.net
copyright ©right 2010-2021。
内容来自网络,如有侵犯请联系客服。zhit325@qq.com