oracle存储过程学习笔记

  1. create or replace procedure 存储过程名(   
  2. 参数名 in 参数类型,   
  3. p_name in varchar2,   
  4. p_password in varchar2   
  5. aaout integer   --返回的参数
  6. ) --这里可以有许多参数
  7. is  
  8. cursor cc is  select did from taskdetails; --循环用到的cursor游标
  9. path varchar2(2000);--定义变量   格式为: 变量名 + 变量类型 +(数值)
  10. tdpath varchar2(2000); 
  11. type array is table of integer(5) index by binary_integer;--oracle数据库没有数组,所有要自己定义,定义为integer5位,下标为integer
  12. arr array;--arr的类型为自定义的array类型
  13. begin  
  14. arr(0):=1;
  15. arr(1):=22;
  16. tdpath :='abc';--变量赋值用:=
  17. for c in cc loop --循环开始
  18. select t.filepath into path from temptask ;--查询出来的值赋给path 用到into 关键字
                 EXCEPTION    --异常捕获 当出现no_data_found异常时 会被捕获
          WHEN NO_DATA_FOUND THEN
                    path := null;
        END;
  19. --还有其他exception需要捕获
  20.            Exception
               when others then
                 rollback;--回滚
  21. end loop;--循环结束
  22. for i in 0..3 loop --循环0到3
  23. null;
  24. end loop;
  25. if arr(0)>0 then
  26. arr(0):=arr(0)-1;
  27. else
  28. arr(0):=arr(0)+1;
  29. end if;
  30. case i --case的用法
               when 0 then
              dbms_output.put_line('1');
               when 1 then
              dbms_output.put_line('2');
               when 2 then
              dbms_output.put_line('3');
               when 3 then
              dbms_output.put_line('4');
            end case;
  31. end;  

猜你喜欢

转载自wb284551926.iteye.com/blog/1682356