How to determine types of subprograms in Oracle Package

前端 未结 2 1929
一个人的身影
一个人的身影 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
    
    0 讨论(0)
  • 2021-01-21 15:59

    You may identify package functions and procedures by using the all_procedures view, examining the data on the method's arguments as it is stored in the data dictionary for a return value:

        SELECT p.object_name
             , p.procedure_name
             , CASE WHEN a.object_id IS NULL THEN 'PROCEDURE' ELSE 'FUNCTION' END ptype
          FROM all_procedures p
     LEFT JOIN all_arguments  a ON (
                                         a.object_id     = p.object_id
                                     AND a.subprogram_id = p.subprogram_id
                                     AND a.data_level    = 0
                                     AND a.argument_name IS NULL
                                   )
         WHERE p.object_name IS NOT NULL
             ;
    
    0 讨论(0)
提交回复
热议问题