How to test PL/SQL procedures and functions?

What are the proven ways to test pl/sql procedures and functions? Specifically, procedures and functions that take cursor variables as IN OUT parameter, OR procedure and functions that takes an array as IN parameter?
Thx.

HI,
One way could by using PL/SQL Develper tool, see Tools/Test Manager...
Also there are others tools, see [Cleaning Up PL/SQL Practices|http://www.oracle.com/technology/oramag/oracle/04-mar/o24tech_plsql.html] and specifically oUnit
Regards,
PS: Your question is very general, could you provide an specific example you are trying?
Edited by: Walter Fernández on Nov 11, 2008 4:04 PM - Adding PS

Similar Messages

  • Are the Pl/sql procedure and function atomic by themself

    i want to ask a question does oracle pl/sql procedure and function support Atomicity for the database by themself , or they became atomic incase we call them using begin -- end;

    You appear to be discussing transaction scope which is completely independent of PL/SQL blocks like procedures or how you call procedures. It's all in where commits (or rollbacks) are issued.
    If you have a procedure like this
    CREATE PROCEDURE p1
    AS
    BEGIN
      INSERT INTO some_table( key, value ) VALUES( 1, 'Foo' );
      INSERT INTO some_table( key, value ) VALUES( 1, 'Bar' );
    END;where the first statement succeeds and the second statement fails as a result of a duplicate key, there will still be a Foo row in the table but the procedure will have thrown an exception. The caller of the procedure may choose to commit or rollback the change-- that will determine whether the first statement's results are made permanent. If you have a procedure like this,
    CREATE PROCEDURE p1
    AS
    BEGIN
      INSERT INTO some_table( key, value ) VALUES( 1, 'Foo' );
      commit;
      INSERT INTO some_table( key, value ) VALUES( 1, 'Bar' );
    END;the commit will make the first insert permanent regardless of whether the second statement fails no matter what the calling code does (that's one reason that putting commits in stored procedures is generally a bad idea-- the caller is in a much better position to know what other uncommitted work has been done and whether it is safe to commit.
    Justin

  • How can I use the procedures and functions in my library

    hello, all
    I have a pl/sql library MYLIB.pld, MYLIB.pll and MYLIB.plx.
    How can I invoke procedures and functions there in JDeveloper?
    Thanks.
    Damon

    I am indeed using ADF BC to re-develop the oracle application.
    Here is my situation:
    We have an oracle form application.
    Our objective is to try to re-use the existing sources in the form application as much as possible:
    1. tons of procedures and functions in a pl/sql library(a file with extension name portfolioLib.pll or portfolioLib.plx);
    2. tons of form-level triggers, data-block triggers and item-triggers;
    3. tons of database stored procedures and triggers;
    After doing a research on JDeveloper, we decide to use ADF Swing+ADF BC to re-develop the application.
    My opinion for the above three kinds of sources in our form application is:
    for 1: we try to move most of procedures and functions into database(except Form build-in);
    for 2: we try to wrap those triggers in a SQLJ class;
    for 3: we try to call database procedures and functions with PreparedStatment or CallableStatement;
    I just do a test on a post-query trigger on a data-block:
    I created a sqlj file, named testSQLJ.sqlj in the test.view package;
    I tried to call it in createInstanceFromResultSet of testDeptVOImpl.java which is test.model package,
    I was told that testSQLJ cannot be found there. why?
    How can I call some classes from test.view package in some classes of test.model?
    I read some documents about how to deal with post-query trigger in JDeveloper: create a view with SQL statement, but it seems that it does not support pl/sql statement there.
    Can you give me some opinion about the above stuff?
    I really appreciate your help.
    Damon

  • Passing arrays through multiple PL/SQL procedures and functions

    I am maintaining a large PL/SQL application. There is a main procedure that is initially called which subsequently passes information to other PL/SQL functions and procedures. In the end an error code and string is passed to PUT_LINE so it can be displayed. What I would like to be able to do is have an array that stores an error code and string for each error that it comes upon during going through each of the procedures and functions. This would involve passing these codes and strings from function to function within the pl/sql application. What would be the best way to implement this and is it possible to pass arrrays or records to other PL/SQL functions? Thanks.

    Here is one simulation ->
    satyaki>
    satyaki>select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - Prod
    PL/SQL Release 10.2.0.3.0 - Production
    CORE    10.2.0.3.0      Production
    TNS for 32-bit Windows: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    Elapsed: 00:00:00.20
    satyaki>
    satyaki>
    satyaki>create or replace type n_array is table of number;
      2  /
    Type created.
    Elapsed: 00:00:07.10
    satyaki>
    satyaki>CREATE OR REPLACE PROCEDURE Get_Array(array_in IN n_array,
      2                                        array_out OUT n_array)  
      3  IS
      4  BEGIN 
      5    array_out := n_array(); 
      6    FOR i IN 1..array_in.count 
      7    LOOP 
      8      array_out.extend; 
      9      array_out(i) := array_in(i) * 2; 
    10    END LOOP;
    11  END Get_Array;
    12  /
    Procedure created.
    Elapsed: 00:00:00.89
    satyaki>
    satyaki>
    satyaki>Create or Replace Procedure Set_Array(myArray IN n_array)
      2  is  
      3    i   number(10);  
      4    rec emp%rowtype;  
      5    w n_array:=n_array(1200,3200);
      6    bucket n_array := n_array();
      7  Begin
      8    Get_Array(w,bucket);  
      9   
    10    for i in 1..myArray.count  
    11    loop 
    12      select *  
    13      into rec 
    14      from emp 
    15      where empno = myArray(i); 
    16      dbms_output.put_line('Employee No:'||rec.empno||' Name:'||rec.ename);
    17      for j in 1..bucket.count
    18      loop
    19        dbms_output.put_line('Commission Sub Type: '||bucket(j));
    20      end loop;
    21    end loop; 
    22  End Set_Array;
    23  /
    Procedure created.
    Elapsed: 00:00:01.33
    satyaki>
    satyaki>
    satyaki>select * from emp;
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          9999 SATYAKI    SLS             7698 02-NOV-08      55000       3455         10
          7777 SOURAV     SLS                  14-SEP-08      45000       3400         10
          7521 WARD       SALESMAN        7698 22-FEB-81       1250        500         30
          7566 JONES      MANAGER         7839 02-APR-81       2975                    20
          7654 MARTIN     SALESMAN        7698 28-SEP-81       1250       1400         30
          7698 BLAKE      MANAGER         7839 01-MAY-81       2850                    30
          7782 CLARK      MANAGER         7839 09-JUN-81       4450                    10
          7788 SCOTT      ANALYST         7566 19-APR-87       3000                    20
          7839 KING       PRESIDENT            17-NOV-81       7000                    10
          7844 TURNER     SALESMAN        7698 08-SEP-81       1500          0         30
          7876 ADAMS      CLERK           7788 23-MAY-87       1100                    20
         EMPNO ENAME      JOB              MGR HIREDATE         SAL       COMM     DEPTNO
          7900 JAMES      CLERK           7698 03-DEC-81        950                    30
          7902 FORD       ANALYST         7566 03-DEC-81       3000                    20
    13 rows selected.
    Elapsed: 00:00:00.28
    satyaki>
    satyaki>declare
      2    v n_array:=n_array(9999,7777);  
      3  begin  
      4    Set_Array(v);  
      5  end;
      6  /
    Employee No:9999 Name:SATYAKI
    Commission Sub Type: 2400
    Commission Sub Type: 6400
    Employee No:7777 Name:SOURAV
    Commission Sub Type: 2400
    Commission Sub Type: 6400
    PL/SQL procedure successfully completed.
    Elapsed: 00:00:00.15
    satyaki>
    satyaki>Regards.
    Satyaki De.

  • PL-SQL Procedures and Functions

    Hi All,
    while reading about PL-SQL Procedures I came across a concept, which states that we can not include bind or host variables in procedures because the compiler cannot resolve the reference to bind variable.
    Can someone please explain it more elaborately.
    Thank you.

    983037 wrote:
    while reading about PL-SQL Procedures I came across a concept, which states that we can not include bind or host variables in procedures because the compiler cannot resolve the reference to bind variable. Correct. This code cannot compile as it needs a bind variable to be bound:
    create or replace function GetEmpName return varchar2 is
      empName emp.ename%Type;
    begin
      select
        e.ename into empName
      from emp
      where emp_no = :BIND_VARIABLE;
      return( empName );
    end;Stored code cannot include bind variables as how is Oracle's compiler to know the data type of +:BIND_VARIABLE+ - or execute the function at run-time when the code is already compiled, but missing a bind call to supply a value for +:BIND_VARIABLE+ ?
    So the code needs to look as follows instead:
    create or replace function GetEmpName( empID number ) return varchar2 is
      empName emp.ename%Type;
    begin
      select
        e.ename into empName
      from emp
      where emp_no = empID;
      return( empName );
    end;The empID PL/SQL variable will be treated (transparently) as a bind variable when the SQL SELECT statement in that function is parsed and executed as a SQL cursor.
    You as caller, however need to supply bind variables when calling this function from an external client (e.g. SQL*Plus, Java, C/C++, etc). E.g.
    --// using sqlplus as example - create 2 sqlplus host variables
    var name varchar2(100)
    var id number
    --// assign a value to a host variable
    exec :id := 12345;
    --// execute the stored function code binding host variables as bind variables
    begin
      :name := GetEmpName( :id );
    end;
    --// display host variable
    print name

  • How to use pl/sql procedure or function as part of validate the entity obj?

    Hi,
    we are migrating from oracle forms to jdeveloper 11g.
    I have a req. that,i wanted to use oracle pl/sql procedure to validate a attribute in an entity created with ADF BC?
    Is it possible to implement this?
    And how to show the error message from pl/sql procedure?
    Regards
    Murali.

    Hi,
    It is possible by using a method validator for the entity attribute.
    Create a transient attribute 'X'.
    In the validation section of the attribute to be validate, choose method validator.
    In the Error Message tab set error message as {0}.
    Below the value for tokentoken should source.X (X is the transient attribute name)
    In the java code of method validator, call the stored procedure and set the value of transient attribute X with the error message from SP.
    Use setX("ErrorMessage").
    Regards,
    Srinidhi

  • Using PL/SQL procedure and function

    In a page i have a VO that uses a Where clause that looks like this
    WHERE attr=package.function
    where the function returns a value of an internal variable valued by another procedure in the package which considers only the Dbuser DBSchema as parameters.
    Do i have to call the procedure in a method like initializeBindigsForPage or i have to put it in another place? And in which mode?
    Thanks Marco

    hi satish,
    i tried ur suggestion, but its shows error like
    declare
    o1 number;
    total_bytes number;
    o3 number;
    unused_bytes number;
    o5 number;
    o6 number;
    o7 number;
    b number:=0;
    str varchar2(2000);
    cursor name is select TNAME FROM TAB WHERE TABTYPE='TABLE';
    begin
    FOR VAL IN name
    LOOP
    DBMS_SPACE.UNUSED_SPACE('XMLUSER',VAL.TNAME,'TABLE',o1,total_bytes,o3,unused_bytes,o5,o6,o7);
    --dbms_output.put_line(VAL.TNAME);
    --dbms_output.put_line(total_bytes);
    --dbms_output.put_line(unused_bytes);
    EXECUTE IMMEDIATE 'select count(*) from '||VAL.TNAME||' ' RETURNING into b;
    --select count(*) into b from VAL.TNAME;
    --execute immediate(str);
    dbms_output.put_line(b);
    insert into space values(VAL.TNAME,total_bytes,unused_bytes,b);
    END LOOP;
    end;
    SQL> @space.sql
    declare
    ERROR at line 1:
    ORA-06547: RETURNING clause must be used with INSERT, UPDATE, or DELETE
    statements
    ORA-06512: at line 19
    wat goes wrong satish?

  • How to test procedures and functions of pl/sql

    I am working as a QA basically i got a new assignment of testing functions and procedures, and packeged bodies. Can any one help me in this matter.
    Please help me.
    Hi i am new to oracle I want to test procedures and functions,
    and packaged bodies of pl/sql.

    It depends on what you meant by "testing". I guess you need to check that routines (functions, procedures, packages etc) in valid state and execute without errors. The simpliest way is to get some development tool like TOAD (http://www.quest.com), Oracle Maestro (http://www.sqlmaestro.com) or PL/SQL Developer (http://www.allroundautomations.com). You can connect with them to database and look at the routine state VALID or INVALID. You can recompile them, run and even debug. I guess this should be enough.
    Alternatively you can do same thing from sqlplus. Of course with lesser comfort. You need to write certain SQL statements. For example i want to find invalid procedures:
    SQL> select OBJECT_NAME, OBJECT_TYPE from USER_OBJECTS where STATUS='INVALID';
    To check how procedures work you need to execute anonymous PL/SQL block like this:
    declare
         /* local variables declaration */
         NAME VARCHAR2(4000);
         PRESIDENT_ID NUMBER(38);
         ID NUMBER(38);
    begin
         /* setting up variables */
         NAME:='MICROSOFT';
         PRESIDENT_ID:='BILLY';
         ID:=NULL;
         /* calling routine */
         GEOMETRY.ADD_COMPANY(NAME,PRESIDENT_ID,ID);
    end;

  • How to get a list of values used in the WHERE filter of stored procedures and functions in SQL Server

    How can I get a list of values (one or more) used in the WHERE filter of stored procedures and functions in SQL Server?
    How can get a list of values as shown (highlighted) in the sample stored procedure below?
    ALTER PROC [dbo].[sp_LoanInfo_Data_Extract] AS
    SELECT   [LOAN_ACCT].PROD_DT,
                  [LOAN_ACCT].ACCT_NBR, 
                  [LOAN_NOTE2].OFCR_CD, 
                  [LOAN_NOTE1].CURR_PRIN_BAL_AMT, 
                  [LOAN_NOTE2].BR_NBR,
    INTO #Table1
    FROM
                    dbo.[LOAN_NOTE1],
                    dbo.[LOAN_NOTE2],
                    dbo.[LOAN_ACCT]
    WHERE
                    [LOAN_ACCT].PROD_DT = [LOAN_NOTE1].PROD_DT
                    and
                    [LOAN_ACCT].ACCT_NBR = [LOAN_NOTE1].ACCT_NBR
                    and
                    [LOAN_NOTE1].PROD_DT = [LOAN_NOTE2].PROD_DT
                    and
                    [LOAN_NOTE1].MSTR_ACCT_NBR = [LOAN_NOTE2].MSTR_ACCT_NBR
                    and
                    [LOAN_ACCT].PROD_DT = '2015-03-10'
                    and
                    [LOAN_ACCT].ACCT_STAT_CD IN
    ('A','D')
                    and
                    [LOAN_NOTE2].LOAN_STAT_CD IN
    ('J','Z')
    Lenfinkel

    Hi LenFinkel,
    May I know what is purpose of this requirement, as olaf said,you may parse the T-SQL code (or the execution plan), which is not that easy.
    I have noticed that the condition values in your Stored Procedure(SP) are hard coded and among them there is a date values, I believe some day you may have to alter the SP when the date expires. So why not declare 3 parameters of the SP instead hard coding?
    For multiple values paramter you can use a
    table-valued parameter. Then there's no problem getting the values.
    If you could elaborate your purpose, we may help to find better workaround.
    Eric Zhang
    TechNet Community Support

  • How to find out list of procedures and functions inside a package

    How I can find out the list of Procedures and Functions inside a Package.

    Look at ALL_PROCEDURES and ALL_ARGUMENTS.

  • How to insert BLOB datatype image using PL/SQL Procedure and SQL Loader

    Hi,
    How to insert an image into database using PL/SQL Procedure and also how to insert using SQL Loader. Please help by giving sample code and process description.
    Thanks,
    Vijay V

    http://asktom.oracle.com/pls/apex/f?p=100:11:0::::P11_QUESTION_ID:232814159006

  • Call a PL/SQL procedure or function from applet

    Could anyone please let me know how I could call a PL/SQL procedure
    or function from a JDBC method from applet with Internet Explorer?

    It depends from where you are calling your PLSQL routine. If it is SQL*Plus then you can use & (ampersand) with the variable to be input at run time.
    If you are executing the PLSQL routine from another application (some front end application) then it's not possible. Because when a procedure is executing at server side, the front end application does not have control, and the control is only transfered back to front end application when the PLSQL routine either completes successfully or throws an exception.
    In either case, you can not go back to the PLSQL routine.
    In this case, what you can do is, write code in your front end application to get that variable value from user and then pass that value to PLSQL routine.

  • Procedure and function diff

    procedure compile once and run at manytime untill it s coding changes
    but
    function every time will be complied
    is it true this statement?????????
    any one help me?????????

    softsuresh wrote:
    is it true this statement?????????
    No. It is a smelly statement.
    Where did you hear it? Can you share the URL? Perhaps there are more to this.. (would hope so, else it would mean someone has very twisted and warped views of how code compilation works).
    There are no differences from a PL/SQL compiler and run-time perspective between a function and a procedure - except when it comes to popping the call stack (as a function will always return a value up the call stack, a procedure not). So procedures and functions are treated the same way by the compiler and the run-time engine. There are no differences between the two so large, that requires the one to be recompiled all the time and the other not.

  • TTClasses interface for PL/SQL procedure and fetching its results

    Hi experts,
    I am using TimesTen Release 11.2.1.3.0;
    I created a simple PL/SQL procedure as follows in timesten-
    Command> create or replace procedure employee(eno in emp.empno%type) is
    > e_name emp.ename%type;
    > begin
    > select ename into e_name from emp where emp.empno = eno;
    > dbms_output.put_line(e_name);
    > end;
    > /
    And then I call it through TTClasses as
    TTCmd cmd, compilecmd;
    compilecmd.Prepare(conn,"alter procedure employee compile;",status);
    cmd.Prepare(conn,"begin employee(1020); end;",status);
    cmd.Execute(..);
    cmd.FetchNext(..);
    Here fetchNext is returning an error -
    [TimesTen][TimesTen 11.2.1.3.0 ODBC Driver]Invalid cursor state
    *** ODBC Error/Warning = 24000, TimesTen Error/Warning = 0
    *** Unable to fetch row for statement: <begin employee(1020); end;>.terminate called after throwing an instance of 'TTError'
    Aborted
    How can I run PL/SQL procedures/functions on TimesTen through TTClasses interface?
    Any help or input would be of great value.
    Thanks

    The issue here is nothing to do with TTClasses. Your PL/SQL procedure executes a SELECT statement (that returns just one row) using an implicit cursor within the PL/SQL procedure and retrieves the value of the ename column into the PL/SQL variable. However it does not them do anything with that value such as pass it back to the caller...
    Similarly, the TTClasses code executes a statement that it is expecting to create an ODBC level cursor 9which thsi PL/SQL invocation will not of course) and it is then trying to fetch from a cursor that does not exist.
    I would recommend that you take a look at the TimesTen PL/SQL documentation (Oracle® TimesTen In-Memory Database PL/SQL Developer's Guide Release 11.2.1) and refer to the section on IN, OUT and IN/OUT parameters. This will show you how you can use OUT parameters to return values to the caller. This technique works fine for ODBC, JDBC and OCi programs but does not sadly currently work with TTClasses. TTClasses has not yet been enhanced to support OUT and INOUT parameters. Of course as you have the source code for TTClasses you could make the necessary modifications yourself.
    I will open a bug requesting that TTClasses support OUT and INOUT parameters but in the meantime if you need this kind of capability you will need to either modify TTClasses yourself or switch to using a different API.
    Chris

  • Diif between Stored procedure and function

    HI
    I want all the differences between Stored procedure and function.
    Even the basic diff is Procedure does not return any value and Function must be...
    Thansk In advance...

    1) Functions are used for computations where as procedures can be used for performing business logic That's an opinion on usage not an actual difference.
    3) You can have DML(insert,update, delete) statements in a function. But, you can not call such a function in a SQL query.Not true. As User defind functons limitations we can use a function that issues DML in a SELECT statement, if it uses the PRAGMA AUTONOMOUS_TRANSACTION.
    4) Function parameters are always IN, no OUT is possibleEasily refutable...
    SQL> CREATE OR REPLACE FUNCTION my_f (p OUT NUMBER) RETURN DATE
      2  AS
      3  BEGIN
      4     p := to_number(to_char(sysdate, 'DD'));
      5     RETURN sysdate;
      6  END;
      7  /
    Function created.
    SQL> var x number
    SQL> var d varchar2(18)
    SQL> exec :d := my_f(:x)
    PL/SQL procedure successfully completed.
    SQL> print d
    D
    18-NOV-05
    SQL> print x
             X
            18
    SQL>
    Stored Procedure :supports deffered name resoultion Example while writing a stored procedure that uses table named tabl1 and tabl2
    etc..but actually not exists in database is allowed only in during creationNot sure what this one is about...
    SQL> CREATE PROCEDURE my_p AS
      2      n NUMBER;
      3  BEGIN
      4     SELECT count(*) INTO n
      5     FROM tab1;
      6  END;
      7  /
    Warning: Procedure created with compilation errors.
    SQL> sho err
    Errors for PROCEDURE MY_P:
    LINE/COL ERROR
    4/4      PL/SQL: SQL Statement ignored
    5/9      PL/SQL: ORA-00942: table or view does not exist
    SQL>
    7) A procedure may modifiy an object where a function can only return a value.An ounce of test is worth sixteen tons of assertion...
    SQL> CREATE OR REPLACE FUNCTION my_f2 RETURN VARCHAR2
      2  AS
      3  BEGIN
      4       EXECUTE IMMEDIATE 'CREATE TABLE what_ever (col1 number)';
      5      RETURN 'OK!';
      6  END;
      7  /
    Function created.
    SQL> exec :d :=  my_f2
    PL/SQL procedure successfully completed.
    SQL> desc what_ever
    Name                                      Null?    Type
    COL1                                               NUMBER
    SQL> I think there are only two differences between a procedure and a function.
    (1) A function must return a value
    (2) because of (1) we can use functions in SQL statements.
    There are some minor difference in allowable syntax but they are to do withj RETURN values.
    Cheers, APC

Maybe you are looking for

  • I would like to be able to edit MP4s in CS5.  I can not open the file. What am I missing?

    I would like to be able to edit MP4s in CS5.  I can not open the file. What am I missing?

  • Bangla character not displayed correctly

    Hi, All   I am work in a multilingual project where some bangla character not displayed properly like "block" in Bangla. The exact apperence of block is ব্লক but in my application it appere as breking character  I am using the latest build of flex sd

  • Weird lFTP og in problem

    My computer has developed a weird FTP fault. When I try to log in to the server via DW8 it takes a long time and then eventually, if it logs in at all, it displays the root folder with no files. There's no + to expand the file listing and after one o

  • Write into a single query

    Hi, I'm fetching supplier, Item, qty information from different tables. Q1: Supplier Name, Quantity are the columns in my select clause, for only one particular item (hard coded). But I want a single query which fulfills my below 2 requirements: 1. c

  • Strange / weird  SPACES behavior

    Guys, I had something weird occurring (for a limited occurrence time) with spaces: I have 6 spaces activated on my MBP: yesterday, when I scrolled vertically the mouse pointer (bluetooth Magic Mouse) toward the bottom of the screen (hence making the