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;

  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM