Question

I see some solutions here for checking for a procedure in a package, but they only work for oracle 9 or 10+.

But is it possible to do this check in Oracle 8i? In Oracle 8 you don't have DBA_PROCEDURES or anything like that.

Any help would be great.

Was it helpful?

Solution

use DBMS_DESCRIBE. it's available in 8i.

see: http://docs.oracle.com/cd/A87860_01/doc/index.htm

if the procedure of function doesn't exist, it will return an ORA-20001 error.

eg

declare 
  V_YOUR_PROC_NAME varchar2(100) := 'MY_PACK.FUNC';
  function proc_exists(p_name varchar2) return boolean
  is
    overload     dbms_describe.number_table;
    position     dbms_describe.number_table;
    c_level      dbms_describe.number_table;
    arg_name     dbms_describe.varchar2_table;
    dty          dbms_describe.number_table;
    def_val      dbms_describe.number_table;
    p_mode       dbms_describe.number_table;
    length       dbms_describe.number_table;
    precision    dbms_describe.number_table;
    scale        dbms_describe.number_table;
    radix        dbms_describe.number_table;
    spare        dbms_describe.number_table;
    idx          integer := 0;
    PROC_NOT_FOUND exception;
    pragma exception_init(PROC_NOT_FOUND, -20001);
  begin
      dbms_describe.describe_procedure(
              p_name,null,null,
              overload,position,
              c_level,arg_name,
              dty,def_val,p_mode,
              length,precision,
              scale,radix,spare);
     return true;
  exception
    when PROC_NOT_FOUND 
    then
      return false;
  end;
begin

  if (proc_exists(V_YOUR_PROC_NAME))
  then
    dbms_output.put_line(' found');
  else
    dbms_output.put_line(' not found');
  end if;
end;

OTHER TIPS

Not sure if this will work on Oracle 8, but try this:

select * 
from   all_procedures 
where  object_name = '<package_name>' 
  and  procedure_name = '<proc_name>'

As it is recommended in this question you may be forced to scan into all_source view.

This should work on Oracle 8i (i haven't been able to test this, due to been on train)

CREATE OR REPLACE FUNCTION check_for_procedure
  (procedure_name IN VARCHAR2)
RETURN BOOLEAN
AS
  procedure_count NUMBER;
BEGIN
    SELECT COUNT(*)
    INTO procedure_count 
    FROM USER_SOURCE 
    WHERE TYPE = 'PROCEDURE'
    AND NAME = procedure_name;
    RETURN 1 = procedure_count;
EXCEPTION
  WHEN OTHERS
  THEN
    RETURN FALSE;
END check_for_procedure;

Unfortunately can't use USER_PROCEDURES or ALL_PROCEDURES because it only exists in Oracle 9i and above

select * from all_objects
where object_name = <object name>
and object_type='PROCEDURE'

Different object type are, it should work in oracle 8 also.

    OBJECT_TYPE
1   JOB CLASS
2   INDEX
3   TABLE SUBPARTITION
4   INDEXTYPE
5   PROCEDURE
6   JAVA CLASS
7   SCHEDULE
8   WINDOW
9   WINDOW GROUP
10  JAVA RESOURCE
11  TABLE PARTITION
12  TABLE
13  TYPE
14  VIEW
15  FUNCTION
16  PROGRAM
17  SYNONYM
18  CONSUMER GROUP
19  EVALUATION CONTEXT
20  DIRECTORY
21  OPERATOR
22  PACKAGE
23  SEQUENCE
24  XML SCHEMA
25  INDEX PARTITION
26  LOB

Finding specific procedure in package

SELECT *
FROM ALL_PROCEDURES
WHERE OBJECT_TYPE = 'PACKAGE' AND
OBJECT_NAME = <package name> AND
PROCEDURE_NAME = <procedure name>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top