码迷,mamicode.com
首页 > 数据库 > 详细

Oracle Stored Procedure demo

时间:2015-02-17 12:52:52      阅读:183      评论:0      收藏:0      [点我收藏+]

标签:

1.how to find invalid status stored procedure and recompile them?

SELECT OBJECT_NAME , status FROM user_objects WHERE OBJECT_TYPE = ‘PROCEDURE‘;

Alter procedure schme.procedurename compile;

缺少练习的学习不是完整的学习,练习才是学习,总结才有思考。

 

SELECT    OBJECT_NAME ,    STATUS FROM    USER_OBJECTS WHERE    OBJECT_TYPE = ‘PROCEDURE‘;

---sample table test(id integer,name varchar2) 
CREATE OR REPLACE PROCEDURE testsp(v_msg VARCHAR2)
AS 
BEGIN
  DBMS_OUTPUT.PUT_LINE(v_msg);
END testsp;

ALTER  PROCEDURE TESTSP COMPILE;

SET SERVEROUTPUT ON;
EXEC testsp(‘oracle stored procedure‘);
EXEC testsp(‘hua xiao yao‘);

CREATE OR REPLACE PROCEDURE procOneOutPara(v_msg VARCHAR2,v_out_p OUT varchar2)
AS 
BEGIN
  DBMS_OUTPUT.PUT_LINE(v_msg);
  v_out_p :=‘execute success‘;
END procOneOutPara;

declare
v_out_msg varchar2(100);
begin
  procOneOutPara(‘hello java‘,v_out_msg);
  dbms_output.put_line(v_out_msg);
end;

CREATE OR REPLACE procedure procCursorReturn(v_id in integer ,outCursor OUT SYS_REFCURSOR )
AS
BEGIN
  open outCursor for
    select * from test where id = v_id;
  exception 
    when others then
    dbms_output.put_line(‘errors occurs‘);
    rollback;
END procCursorReturn;
 
DECLARE 
  testCursor SYS_REFCURSOR;
  mytest   test%ROWTYPE;
BEGIN
 procCursorReturn(5,testCursor);
  LOOP
    FETCH testCursor INTO mytest;
      EXIT WHEN testCursor%NOTFOUND;
      dbms_output.put_line(mytest.name);
  END LOOP; 
  CLOSE testCursor;
 END;


 

Oracle Stored Procedure demo

标签:

原文地址:http://www.cnblogs.com/huaxiaoyao/p/4295127.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!