Skip to Main Content
  • Questions
  • Jave Stored Procedure vs PL/SQL Stored Procedure

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Peter.

Asked: March 11, 2001 - 1:39 am UTC

Last updated: October 31, 2006 - 9:59 am UTC

Version: 8.1.6

Viewed 1000+ times

You Asked

Hi Tom:

can you explain between Java Stored Procedure vs PL/SQL Stored Procedure?

1. JSP is multi-threaded vs PL/SQL SP is single-threaded?
2. JSP run byte code in Oracle JVM vs byte code in Oracle PL/SQL engine? which one is more efficient?

Thanks for your help!
Peter Cheng

and Tom said...

The difference is that you code one in java and the other in PLSQL. thats it quite simply. They are both stored procedures and exhibit the same behavior in that respect.

1) jsp = java server page, not a java stored procedure. A java stored procedure could be multi-threaded (that is supported) however it is not recommended at all. It is recommended you do not use threads in a java stored procedure.

2) There is the Oracle jvm in the database which is architected in much the same was as the PLSQL vm is (PLSQL runs in a VM just like java).

As to which is more efficient -- if you are doing "data heavy" stuff, plsql will be more efficient both in processing resources as well as time to code (the language is written to do SQL stuff). Java is not.

I use java stored procedures when I find I cannot use PLSQL. For example, sending an email with an attachment - plsql = hard, java = easy. Loop over the rows in a table and do something, plsql = easy, java = hard -- i use plsql there.



Rating

  (9 ratings)

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

Comments

A reader, February 07, 2002 - 6:55 pm UTC


rumors of desupporting java in database

A reader, July 17, 2003 - 12:47 pm UTC

Hi Tom
I have heard rumors that Oracle may be planning
to desupport java in database in future?

Have you heard anything of this sort?

Thanx for this awesome site!

Menon:)

Tom Kyte
July 17, 2003 - 3:45 pm UTC

no, not true. we moved the j2ee containers out of the database into the middle tier but java in the db is alive and kicking

thanx!

A reader, July 17, 2003 - 3:51 pm UTC

btw, why was the decision made to move the j2ee containers
out of db? performance reasons? Any urls that discuss
this issue would be great!

Thank you!

Menon:)

Tom Kyte
July 17, 2003 - 4:03 pm UTC

no urls, just practical reasons -- performance being one.

A reader, July 21, 2003 - 4:58 am UTC

jsp = java server page

and there I was thinking it meant

Jackson's method of Structured Programming.


Multi threading

Phil, November 05, 2003 - 4:34 am UTC

from above "A java stored procedure
could be multi-threaded (that is supported) however it is not recommended at
all. It is recommended you do not use threads in a java stored procedure."

why is it recommended you do not use threads in a java stored procedure?

thanks

Tom Kyte
November 05, 2003 - 8:40 am UTC

because only one thread at a time really runs at a time. java stored procedures should be

a) simple
b) to the point
c) very very small
d) doing only that which plsql cannot do

so they really don't need threads anyway.

JSP

Tony Andrews, November 05, 2003 - 11:20 am UTC

<QUOTE>
java stored procedures should be

a) simple
b) to the point
c) very very small
d) doing only that which plsql cannot do
</QUOTE>

Good advice. However, I worry that those that like Java especially will tend to merely use JSPs instead of PL/SQL procedures as a matter of course.

Where I currently work we have a very mature application that does a lot of its core database work in Pro*C, merely because stored procedures weren't around when it was first written. I heard recently there were plans for a rewrite - in Java! The reason given was that there are more Java programmers in the "market" than PL/SQL programmers. What kind of stupid reason is that?

Tom Kyte
November 05, 2003 - 6:17 pm UTC

ask them how many DATABASE programmers there are - and what language they program in.

Dime a Dozen

Dan Clamage, November 05, 2003 - 4:12 pm UTC

They're thinking, more = cheaper. Like VB programmers, dime a dozen. They may also be thinking, who will be maintaining the system in 10 years?

I read one performance test between Java and PL/SQL. For database-intensive work, PL/SQL beat the snot out of Java. For complex calculations, Java was faster. I guess because Java has an optimized math runtime library. If you native-compile PL/SQL, you'll get a huge performance boost.

Tom Kyte
November 06, 2003 - 7:29 am UTC

wait'll 10g ;) then there goes that math argument too

To Tony:

Jens, November 06, 2003 - 7:04 am UTC

Tony Andrews from London, UK wrote:

<QUOTE>
The reason given was that there are more Java programmers in the "market"
than PL/SQL programmers. What kind of stupid reason is that?
</QUOTE>

What a bad decision! But Oracle has pushed it sometimes ago when 99% of every Oracle magazine was full of Java: Jave here and Java there and nobody wants to hear about new features in the databse or pl/sql. If you pick up some of these "more Java programmers from the market" you take somebody in your team who has perhaps a good java knowledge but a bad understanding of the database und query processing and so on. I met a lot of good java programmmers who made a good job as database-performance-killer!

Somebody who knows PL/SQL has a better knowledge in Oracle and helps you to bring back the licence costs of your oracle installation into your company needs. But for these only-java-guys you don't need oracle.

Bye,

Jens

Bye,

Jens



Why Java Stored Procedure

Arindam Mukherjee, October 31, 2006 - 9:09 am UTC

Respected Mr. Tom,

Right now I am learning Java Stored Procedure due to my project requirement. They use this for batch processing. I could not understand why I should use “Java Stored Procedure” when PL/SQL is enough to get same mileage. What’s the benefit of this over Pl/SQL procedure?

Regards,


Tom Kyte
October 31, 2006 - 9:59 am UTC

you have hit the nail on the head here.

Indeed, what ARE the advantages?


PLSQL is almost certainly the language you should be using here for "batch processing". Java would be somewhat less efficient to code and process the data with.

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