Search Results


Tuesday, November 04, 2008

Callable Statement

How to Call a PL/SQL block from OA framework


You can call PL/SQL block from the OA Framework using callable statement. Use the following code from application module.


import java.sql.CallableStatement;
import oracle.apps.fnd.common.VersionInfo;
import
java.sql.SQLException;


CallableStatement
updateStmt = null;

try
{
// Put your PL/SQL block in a String variable.

String
deleteStmt = "begin delete test_table where header_id = :1; "+
" :2 = xxx_pkg.yyy_function(); end;";

OADBTransaction
txn = getOADBTransaction();

// Pass the PL/SQL block to the callable Statement

updateStmt = txn.createCallableStatement(deleteStmt, 1);


// Set all the bind variables before calling the execute command

updateStmt.setInt(1, headerIdToDelete);

// And register the output parameter types
updateStmt.registerOutParameter(2, Types.DOUBLE);

updateStmt.executeUpdate();

// After execute you can get the value of pl/sql block output
Number amount = new Number(updateStmt.getDouble(2));
updateStmt.close();


// Commit the transaction in the database
txn.commit();


}
catch(SQLException sqle) {
updateStmt.close();

}



If you want to call pl/sql from the controller then get the application module from the pageContext.
And then get the db transaction from the application module
OADBTransaction txn = pageContext.getApplicationModule(webBean).getOADBTransaction();


Article By:
Prasanna Jayaraman

Please post your Ideas and Comments

17 comments :

Anonymous said...

Hi,
Thanks for dropping by.
Thnks for the motivation too.
Just my effort to give back what i am passionate about.
Without guys like u,sumit and likes,this wouldn have been possible,cos i would have sucked at my job:-)

Gravity said...

GoodWork.
One little thing : I implemented this code of calling procedure. I was trying to delete a configuration through a procedure of an inbuilt package. Record successfully got deleted through OAF page, but when I queried the tables, it was still there.
So I added - txn.commit(); after updateStmt.close();
And it did the work.
Thanks a lot for such a beautiful article.
Jyo

Pras said...

Thanks for your comments.
I'll include the txn.commit() in the articles.

Gravity said...

Hi Prasanna,
can you help me with this.
I am trying to call a seeded procedure from OAF page which deletes records from different tables.
If I try to delete a non-existent record it doesnt throw any error message.
How can I write a code to make a check and throw message that this record doesnt exist.
Thanks

Pras said...

After delete statement check if SQL%NOTFOUND then raise the user defined exception from pl/sql block.

You can catch the sql exception in Catch block of the Java code.

--Prasanna

Rahul said...

hi,
I tried to update the some parameters in a table using this way but I am getting an exception at the executeupdate method..

Please help me

Pras said...

Hi Rahul,

Ensure that all the bind variables are bound.

Before trying out this method, test you pl/sql code in sql*plus or sql developer.

If your not able to figure it out, then post the exception here..

--Prasanna

Anonymous said...

Hi Prasanna,

i have 2 tables, in that two tables one column have same attribute column. when i update the first table through OAF page, i wanted to effect updated value in second table also. i have followed same as you mentioned in callable statements.i wrote pl/sql procedure and call that proc into that OAFRAMEWORK by using callble . here first time i updated in the page, updated value is effecting into the first table while second table not effected the updated value. again i am trying to update the page this time in second table effected with first time updation value,while first table updated correctly. suppose i updated again in the page this time in second table effected with second time updation value, while first table updated correctly.this process continuing...

Thanks,
krishna

Pras said...

Hi krishna,

If you want to update a Value in another page, don't use callable statment.

Because the callable statement bypasses the (Middleware)View Object and directly updates the database.

You need to do
1. vo.executeQuery()
2. Row row = vo.findbyPrimaryKey(...); //get the row you want to update.
3. row.setAttribute("ATTXX","value");
4. Now commit the transaction using am.getDBTransaction.commit();

this will update the value in other table as well as update the database.


--Prasanna

Unknown said...

Hi Prasanna ,

I have requirement to call a custom procedure by the click of a button (available for each record in the table) . I need to pass few parameters to the procedure which i can get from the table . Could you please let me know the approach to achieve this .

Thanks

Pras said...

Hi sujatha,

1. capture the button even in the processFormRequest().
2. get the values from the table like
Row vrow = am.getFindViewObject("XXvo").getCurrentRow();
String empid = vrow.getAttribute("XXXEmpId");

3. Then use example given in the article to call the pl/sql procedure and to pass the values.


--Prasanna

Anonymous said...

Thanks for your response Prasanna.
I captured the parameters via the button for each row and invoked the method in AM . I wasn't sure where to place the call to the DB procedure.

Pras said...

Hi suzy,

what you did is correct.
It has to be called in the AM.

--Prasanna

Unknown said...

Hi Prasanna,

Could you please tell me how do we call the Workflow Concurrent Progs from OAF?

Unknown said...

Hi Prasanna,

Could you please tell me how do we call the Workflow Concurrent Progs from OAF?

mahakk01 said...

I never tried callable statement. The syntax for the callable statement is easy. I understand where to use callable statement. You can paste the syntax and see the result. You are effort deserves appreciation. Thanks for the post.
oracle ebs r12

Vamshi Surapaneni said...

hi i am doing OAF from which was already done in D2K.

in D2K they used two tables for insert they used Global Temp table
and updating in Standard table can give ex for this plz.