sqlplus中存储过程的相关操作

--登录:
> sqlplus ( < username > [/ < password > ][@ < connect_identifier > ] | /) [AS SYSDBA | AS SYSOPER] | /NOLOG
SQL> desc   user_source;
--查看:
SQL> select TEXT from user_source where TYPE ='PROCEDURE' and NAME = 'Your_Procedure_name' ;
--执行:
SQL> var  out_var  number
exec  Your_Procedure_name ( '' , '' , '' ,:out_var)
print  out_var

--编译:
alter procedure procedure_name compile;

--重新编译所有invalid存储过程:
spool ExecCompProc.sql
select 'alter procedure '||object_name||' compile;' From all_objects where status = 'INVALID' and object_type = 'PROCEDURE';
spool off
@ExecCompProc.Sql;

整理成一个存储过程
Create Or Replace Procedure Zl_Compile_Invalid_Procedure As
Strsql Varchar2(200);
Begin
For x In (Select Object_Name From All_Objects Where Status = 'INVALID' And Object_Type = 'PROCEDURE') Loop
  Strsql := 'Alter Procedure ' || x.Object_Name || ' Compile';
  Begin
      Execute Immediate Strsql;
      Exception
          --When Others Then Null;    
     When OTHERS Then dbms_output.put_line(Sqlerrm);    
  End;
End Loop;
End;

执行
exec Zl_Compile_Invalid_Procedure;
如果要看到无法重编译的过程的出错信息,需要执行前设置set serverout on

你可能感兴趣的:(sql)