Skip to Main Content
  • Questions
  • Java StoredProcedure Vs PL/SQL StoredProcedure

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Raja.

Asked: June 13, 2000 - 10:35 am UTC

Last updated: January 23, 2004 - 4:10 am UTC

Version: 8.1.6

Viewed 1000+ times

You Asked

Iam using java application to call a stored procedure written in PL/SQL.It is taking lot of time to execute. Should i write the stored procedure in java. Pls let me know which will better in performance issue. We have lot of packages created in PL/SQL. If performance is the main issue then do we need to convert all the packages to java. Let me know the situation where i should go fro java and where i should go for PL/SQL.

Thanks for any help.



regards,
Rajasekhar.

and Tom said...

Java can be faster then plsql, it can be slower. Existing PLSQL can always be tuned to go faster as well. Do not recode all of your PLSQL in java, that would be a waste of time. The interaction between Java and PLSQL is potentially faster then the interaction between Java and a Java stored procedure (for Java to call a java stored procedure we must take java types -> turn them into sql types -> turn them into java types and do the reverse on the way out. for Java to call a plsql stored procedure we must take a java type -> turn it into a sql type and do the reverse on the way out)

My experience shows that

- if you give me a non-trivial Java stored procedure, I'll be able to write it to run in PLSQL faster.

- if you give me a non-trivial PLSQL stored procedure, I'll be able to write it to run in Java faster.

point being -- they are about the same, there are times when java will beat plsql and vice versa.

The problem is not in the execution speed of PLSQL in as much as it will be an untuned series of queries/statements in your PLSQL routine.

I suggest you look at:

o timed_statistics
o SQL_TRACE
o and especially TKPROF

and failing that, see the dbms_profiler package for source code profiling of PLSQL.

To get started with TKPROF, which will probably identify your performance bottleneck, it'll find that query(s) that is causing your slowness, see

</code> http://docs.oracle.com/cd/A81042_01/DOC/server.816/a76992/ch14_str.htm#1018

If you have problems interpreting the results of TKPROF, feel free to follow up with that.

The profiler, which should only be used AFTER your queries are running at the speed of light, can be read about here:

http://docs.oracle.com/cd/A81042_01/DOC/server.816/a76936/dbms_pro.htm#1003424 <code>

....


Rating

  (4 ratings)

Is this answer out of date? If it is, please let us know via a Comment

Comments

How to update or insert into a SQLServer without using Transparent Gateway?

A reader, June 27, 2002 - 2:10 pm UTC

Hi Tom,
In your book (one on one, p844)you wrote:
"But if we only need to run a simple query or update on DB2, without any of the other fancy features, then we could simply load the DB2 Java JDBC drivers into the database, and do it that way (this doesn't apply DB2, of course)."

We have Oracle 8.1.7.0.0. (standard edition for that one)database and want simply insert or update (maybe delete) into some tables in SQLServer 7.0, can we do it using the method mentioned without using TG(the above) in your book? If we can, can you please show us an example about the steps and details or recommend some documents that we can follow.
Thank you very much in advance.

Tom Kyte
June 27, 2002 - 2:25 pm UTC

You can do that - just load their type 4 (thin) jdbc drivers into the database with loadjava.

see
</code> http://asktom.oracle.com/pls/asktom/f?p=100:11:::::P11_QUESTION_ID:4406709207206 <code>
for another way as well if you have "odbc"

I have to ask

Doug, June 27, 2002 - 10:40 pm UTC

Sorry - what do you mean by "non-trivial" ?

Tom Kyte
June 28, 2002 - 6:53 am UTC

non-trivial means "more complex then System.out.println( "Hello World" ) or dbms_output.put_line( 'Hello World' )".

Something of enough complexity. If it contains sufficient complex logic -- that means the problem it was solving was complex -- meaning there are many ways to solve the problem -- meaning, I'll find a faster algorithm in the other language hence besting the first language.

Helena Markova, February 12, 2003 - 3:48 am UTC


How to load thin jdbc Drivers for SqlServer to the Oracle Database

pasko, January 23, 2004 - 4:10 am UTC

Hi Tom,

Thanks for the Great support you give to the Oracle Communtity :

I need some Help on how to load the Type 4 (thin) jdbc Drivers for SqlServer into the Oracle Database using the loadjava utility.

Do you know where to find them ?

Thanks in advance.


More to Explore

PL/SQL demos

Check out more PL/SQL tutorials on our LiveSQL tool.

PL/SQL docs

PL/SQL reference manual from the Oracle documentation library