oracle存储过程(二):两种循环+基本增删改查操作
增:
create or replace procedure mydemo07(ids in int, username in varchar,userpass in varchar, userage in int)
as
begin
-- insert into students(id,username,userpass,userage)--增
-- values(ids,username,userpass,userage);
-- delete from students where id=ids;--删
--update students set userage=100 where id=ids;--改
commit;
end;
begin
mydemo07(10,'a','b','17');
end;
---------------------------
create or replace procedure mydemo08(ids in int, age out int)
as
begin
select userage into age from students where id=ids; --查
commit;
end;
declare
ids int;
age int;
begin
ids:=1;
myDemo08(ids=>ids,age=>age);
dbms_output.put_line('age='||age);
end;
for循环
create or replace procedure mydemo09 as begin for stu in (select * from students) loop if (stu.id<5) then dbms_output.put_line(stu.id); end if; end loop; commit; end; begin mydemo09(); end;
while循环
create or replace procedure test_while_loop as n_count number := 0; begin while n_count < 10 loop dbms_output.put_line(n_count); n_count := n_count + 1; end loop; end; begin test_while_loop(); end;
作者:
i孤独行者
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。