how to test a oracle package

Posted on 2009-02-10
Last Modified: 2013-12-19
I created a oracle package How do I test all the functions and procedures in it
Question by:vishnut28
    LVL 73

    Expert Comment

    same as you would if the procedures and functions were standalone.

    You call of them with whatever test data makes sense to validate/stress them.

    If you have some un-exposed functions/procedures.  I suggest you expose them for the purposes of testing and then remove them from the package specification before releasing to GA.
    LVL 73

    Accepted Solution

    select your_package.your_function('param1','param2') from dual;

    v_result number; -- or whatever type makes sense
         your_package.your_procedure('param1','param2', v_result);
    LVL 3

    Expert Comment

    A lot of it depends on what the functions and procedures are intended to do, but some things that will be helpful with testing are developer tools, like sqlplus or TOAD, and the dbms_output package.  For example, if you want to test a function, then you can set up an anonymous PL/SQL block in a little script file that returns a value into your variable, then display the variable contents to confirm that it worked.  Like this:

    set serveroutput on
      v_return_value NUMBER;
      v_return := mypackage.myfunction;
      dbms_output.put_line('v_return = ' || v_return);

    Procedures are a little more difficult because they're usually more complex, but basically you want to set up a test case and run the procedure to see if the expected results occur.  If not, then you can insert some debugging statements (provided you don't have a source-level debugger) that display results or write results to a logging table or file.  Be sure and test all possible scenarios - don't just run through the most common scenario and assume that all use cases will succeed.

    Finally, it is important to code your functions and stored procedures to trap for unexpected SQL errors and report the results.  Do a little research on the EXCEPTION clause in PL/SQL if you're not already familiar with it.
    LVL 18

    Expert Comment

    check this out for testing oracle PL/SQL ...

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    PRTG Network Monitor: Intuitive Network Monitoring

    Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

    Working with Network Access Control Lists in Oracle 11g (part 2) Part 1: Previously, I introduced the basics of network ACL's including how to create, delete and modify entries to allow and deny access.  For many…
    Using SQL Scripts we can save all the SQL queries as files that we use very frequently on our database later point of time. This is one of the feature present under SQL Workshop in Oracle Application Express.
    This video shows information on the Oracle Data Dictionary, starting with the Oracle documentation, explaining the different types of Data Dictionary views available by group and permissions as well as giving examples on how to retrieve data from th…
    This video shows how to configure and send email from and Oracle database using both UTL_SMTP and UTL_MAIL, as well as comparing UTL_SMTP to a manual SMTP conversation with a mail server.

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now