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;

  

 

posted @ 2018-07-04 20:20  i孤独行者  阅读(37374)  评论(2编辑  收藏  举报