Unable to find procedure in DBA_PROCEDURES view

2019-06-05 03:58发布

I have created a procedure :

create or replace procedure gg as
begin
insert into book values ('prashant','prashant','prashant');
commit;
end;
/

Procedure has been created successfully.Now i want to check the package name for the corresponding procedure but i am not able to do so.

I am using the below query :

 > SELECT *
        FROM SYS.DBA_PROCEDURES
        WHERE procedure_name ='gg';

Its giving 0 rows selected.Please help.

2条回答
▲ chillily
2楼-- · 2019-06-05 04:10

NOTE Please look at the UPDATE section for correct answer.

The procedure name cannot be in lower case in the DBA_PROCEDURES view. Use upper case, or apply UPPER function.

SELECT *
  FROM SYS.DBA_PROCEDURES
 WHERE procedure_name ='GG';

UPDATE

The only case when you could have the name in lower case is if you enclose it within double-quotation marks while compiling.

For example,

SQL> CREATE OR REPLACE
  2  PROCEDURE "p"
  3  AS
  4  BEGIN
  5    NULL;
  6  END;
  7  /

Procedure created.

SQL> SELECT object_name, procedure_name, object_type FROM user_procedures where procedure_name='p';

no rows selected

SQL>

But still the above view will not return any result for PROCEDURE_NAME.

Reason

PROCEDURE_NAME column will only have the procedure name for the procedures which are part of a PACKAGE. For STAND ALONE PROCEDURES you need to use OBJECT_NAME.

SQL> -- stand alone procedure in lower case
SQL> CREATE OR REPLACE
  2  PROCEDURE "p"
  3  AS
  4  BEGIN
  5    NULL;
  6  END;
  7  /

Procedure created.

SQL>
SQL>  -- package
SQL> CREATE OR REPLACE
  2  PACKAGE test_p
  3  IS
  4    PROCEDURE p;
  5  END test_p;
  6  /

Package created.

SQL>
SQL> -- package body with a procedure
SQL> CREATE OR REPLACE
  2  PACKAGE BODY test_p
  3  IS
  4  PROCEDURE p
  5  IS
  6  BEGIN
  7    NULL;
  8  END;
  9  END test_p;
 10  /

Package body created.

SQL>
SQL> SELECT object_name, procedure_name, object_type FROM user_procedures;

OBJECT_NAME     PROCEDURE_NAME  OBJECT_TYPE
--------------- --------------- ---------------
TEST_P          P               PACKAGE
p                               PROCEDURE
TEST_P                          PACKAGE

SQL>

So, as you can see, the procedure_name is only having the package's procedure, however the stand-alone procedure is only listed under object_name.

查看更多
Anthone
3楼-- · 2019-06-05 04:17

The query I use is:

SELECT * FROM User_Procedures WHERE NVL(Procedure_Name,Object_Name) = 'PROCNAME';
查看更多
登录 后发表回答