How to determine types of subprograms in Oracle Package

前端 未结 2 1932
一个人的身影
一个人的身影 2021-01-21 15:44

This is best explained with an example. Given the below database objects:

CREATE OR REPLACE PROCEDURE TEST_PROCEDURE IS
BEGIN
  NULL;
END;
/

CREATE OR REPLACE F         


        
2条回答
  •  时光取名叫无心
    2021-01-21 15:49

    Similar idea to @collapsar, but using the argument position to differentiate between a procedure and a function. A function has an (unnamed) argument in position zero, in addition to any formal parameters which start at position one. Procedures don't have the position zero argument.

    select up.object_name, up.procedure_name,
      case ua.position when 0 then 'FUNCTION' else 'PROCEDURE' end as type
    from user_procedures up
    left join user_arguments ua
    on ua.object_id = up.object_id
    and ua.subprogram_id = up.subprogram_id
    and position = 0
    where up.object_type = 'PACKAGE'
    and up.object_name = 'TEST_PACKAGE'
    and up.procedure_name is not null;
    
    OBJECT_NAME                    PROCEDURE_NAME                 TYPE    
    ------------------------------ ------------------------------ ---------
    TEST_PACKAGE                   TEST_FUNCTION                  FUNCTION 
    TEST_PACKAGE                   TEST_PROCEDURE                 PROCEDURE
    

提交回复
热议问题