Professional Documents
Culture Documents
Written by
Steven Feuerstein, PL/SQL Evangelist, Quest Software, Inc. Daniel Norwood, Senior Product Manager, Quest Software, Inc.
TECHNICAL BRIEF
2011 Quest Software, Inc. ALL RIGHTS RESERVED. This document contains proprietary information protected by copyright. No part of this document may be reproduced or transmitted in any form or by any means, electronic or mechanical, including photocopying and recording for any purpose without the written permission of Quest Software, Inc. (Quest). The information in this document is provided in connection with Quest products. No license, express or implied, by estoppel or otherwise, to any intellectual property right is granted by this document or in connection with the sale of Quest products. EXCEPT AS SET FORTH IN QUEST'S TERMS AND CONDITIONS AS SPECIFIED IN THE LICENSE AGREEMENT FOR THIS PRODUCT, QUEST ASSUMES NO LIABILITY WHATSOEVER AND DISCLAIMS ANY EXPRESS, IMPLIED OR STATUTORY WARRANTY RELATING TO ITS PRODUCTS INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT. IN NO EVENT SHALL QUEST BE LIABLE FOR ANY DIRECT, INDIRECT, CONSEQUENTIAL, PUNITIVE, SPECIAL OR INCIDENTAL DAMAGES (INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOSS OF PROFITS, BUSINESS INTERRUPTION OR LOSS OF INFORMATION) ARISING OUT OF THE USE OR INABILITY TO USE THIS DOCUMENT, EVEN IF QUEST HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. Quest makes no representations or warranties with respect to the accuracy or completeness of the contents of this document and reserves the right to make changes to specifications and product descriptions at any time without notice. Quest does not make any commitment to update the information contained in this document. If you have any questions regarding your potential use of this material, contact: Quest Software World Headquarters LEGAL Dept 5 Polaris Way Aliso Viejo, CA 92656 www.quest.com email: legal@quest.com Refer to our Web site for regional and international office information.
Trademarks
Quest, Quest Software, the Quest Software logo, AccessManager, ActiveRoles, Aelita, Akonix, AppAssure, Benchmark Factory, Big Brother, BridgeAccess, BridgeAutoEscalate, BridgeSearch, BridgeTrak, BusinessInsight, ChangeAuditor, ChangeManager, Defender, DeployDirector, Desktop Authority, DirectoryAnalyzer, DirectoryTroubleshooter, DS Analyzer, DS Expert, Foglight, GPOADmin, Help Desk Authority, Imceda, IntelliProfile, InTrust, Invirtus, iToken, I/Watch, JClass, Jint, JProbe, LeccoTech, LiteSpeed, LiveReorg, LogADmin, MessageStats, Monosphere, MultSess, NBSpool, NetBase, NetControl, Npulse, NetPro, PassGo, PerformaSure, Point,Click,Done!, PowerGUI, Quest Central, Quest vToolkit, Quest vWorkSpace, ReportADmin, RestoreADmin, ScriptLogic, Security Lifecycle Map, SelfServiceADmin, SharePlex, Sitraka, SmartAlarm, Spotlight, SQL Navigator, SQL Watch, SQLab, Stat, StealthCollect, Storage Horizon, Tag and Follow, Toad, T.O.A.D., Toad World, vAutomator, vControl, vConverter, vFoglight, vOptimizer, vRanger, Vintela, Virtual DBA, VizionCore, Vizioncore vAutomation Suite, Vizioncore vBackup, Vizioncore vEssentials, Vizioncore vMigrator, Vizioncore vReplicator, WebDefender, Webthority, Xaffire, and XRT are trademarks and registered trademarks of Quest Software, Inc in the United States of America and other countries. Other trademarks and registered trademarks used in this guide are property of their respective owners.
Updated[January, 2011]
Why Every Java Developer Should Also Know and Use Oracle PL/SQL
Contents
Contents .........................................................................................................................................................................1 Introduction ....................................................................................................................................................................3 Choosing the Right Tool for the Job ............................................................................................................................... 4 The Role Oracle PL/SQL Plays in Application Development .........................................................................................5 Tight Integration with SQL ..........................................................................................................................................5 High Performance.......................................................................................................................................................5 Application Management ............................................................................................................................................5 Highly Secure Applications .........................................................................................................................................5 Integrated Application Development Tool Key ...............................................................................................................6 Using Toad from Within Eclipse...................................................................................................................................7 Toad Extension for Eclipse ......................................................................................................................................7 Installing Toad Extension for Eclipse ..........................................................................................................................7 Connecting Your Oracle Database ............................................................................................................................. 8 Opening a Stored Procedure .................................................................................................................................... 11 Conclusion ................................................................................................................................................................... 14 Resources ................................................................................................................................................................ 14 About the Authors ........................................................................................................................................................ 15
Why Every Java Developer Should Also Know and Use Oracle PL/SQL
Introduction
Java is one of the most popular general-purpose programming languages in the world. You can run Java on virtually every operating system and computer. You can even run Java code from within the Oracle database. Oracle PL/SQL is a proprietary database programming language, used primarily within the Oracle database context, (though it can now be used with some versions of IBM DB2). It has a relatively narrowly defined purpose and does not support nearly the breadth and depth of features that Java does. The PL/SQL developer community is relatively small and isolated from the rest of the programming world. As Quest Software's PL/SQL evangelist, I recommend to all PL/SQL developers that they learn the basics of Java. Even if you are not going to become a full-time Java programmer, you should at least understand how you can "escape" to Java from PL/SQL to implement a user requirement that cannot be handled within the constraints of the PL/SQL language. In this paper, I argue the converse: that every Java developer (well, at least those who write applications that run against an Oracle database) should also learn the rudiments of Oracle PL/SQL. This recommendation will come as a surprise to (and, I expect, be resisted by) many Java developers. Why learn about Oracle PL/SQL when Java can do everything we need?
Why Every Java Developer Should Also Know and Use Oracle PL/SQL
Eric Knipp, Jim Duggan, Ross Altman, "Predicts 2011: Anticipate Application Development Challenges Arising From Cost Optimization, Agile Methodologies and Multichannel Customer Engagement," Gartner (2010): 6-7.
Why Every Java Developer Should Also Know and Use Oracle PL/SQL
High Performance
One of the most important advantages of PL/SQL is that you can execute a single block that contains multiple SQL statements. By combining all statements into a single block, you can drastically reduce network traffic between the database and an application. In addition, PL/SQL offers unique language features to optimize the execution of SQL statements. FORALL and BULK COLLECT can improve SQL performance by an order of magnitude over SQL inside a loop. Pipelined table functions can be used to reduce the user perception of elapsed time.
Application Management
When you compile a stored program unit into the database, Oracle maintains information about dependencies between database objects. As those objects change, Oracle automatically invalidates and forces recompilation of dependent objects. In addition, Oracle's shared memory facilities, in which PL/SQL code participates, improve the scalability of applications that are built on PL/SQL.
Why Every Java Developer Should Also Know and Use Oracle PL/SQL
Why Every Java Developer Should Also Know and Use Oracle PL/SQL
Why Every Java Developer Should Also Know and Use Oracle PL/SQL
Figure 1: Install New Software screen. (For those of you in corporate environments where this isnt possible, you can download a ZIP file from www.ToadExtensions.com.) At this point, Toad Extension for Eclipse will work like any other Eclipse perspective. As youre working with your Java code, simply switch perspectives to begin working on your PL/SQL code within Eclipse.
Why Every Java Developer Should Also Know and Use Oracle PL/SQL
Figure 2: Specify the location of your driver. Now lets create your first connection. Click on the New Connection button in the Connections pane (Figure 3).
Figure 3: New Connection button. This will open a new dialog where you can enter the server information and your credentials. If you have an Oracle client configured on your machine, I would recommend using that method to connect (Figure 4). This will give you quick access to an Oracle database server. Otherwise, you can try a direct connection over TCP/IP (Figure 5). Either way, save your connection information and right click on it to connect.
Why Every Java Developer Should Also Know and Use Oracle PL/SQL
Why Every Java Developer Should Also Know and Use Oracle PL/SQL
10
Figure 5: Connection screen (Direct TCP/IP connections). Were in! Now lets get to work.
Why Every Java Developer Should Also Know and Use Oracle PL/SQL
11
As you can see, theres a red X in the left margin as well as a red block in the scroll bar on the right, both indicating the location of our error. However, Toad Extension for Eclipse doesnt stop there! Note that our code is underlined at the location of our error, showing us exactly where the error is. Furthermore, when you try clicking on the red X on the left, youll be presented with more detailed information about the error (Figure 7). Pretty helpful info Toad Extension for Eclipse to the rescue! (OK, OK. This is obviously a very simple example, but I think it works for our purposes.)
Figure 7: Detailed error information. So lets fix our error and recompile to procedure. To do this, use the Edit Procedure button at the top of the window (Figure 8). This opens the procedure in a new window where we can make some edits.
Why Every Java Developer Should Also Know and Use Oracle PL/SQL
12
With our changes in place, we can use the green play button to store the procedure in the database and recompile it (Figure 9). Notice that our error is now resolved and our code compiles cleanly!
Figure 9: Save the code and recompile it into the database. At this point, you may want to do some deeper validation of your code by debugging or creating/running some unit tests. These are features that we hope to add in short order! But for now, you can switch perspectives again to pick up where you left off with your Java code or maybe hang here a while longer and run some queries to validate some test data either way, youll be able to maintain context within your favorite IDE, Eclipse!
Why Every Java Developer Should Also Know and Use Oracle PL/SQL
13
Conclusion
With Toad, you can leverage existing skill sets while growing to meet tomorrows demands. You will continue to have a simple, consistent way to build, access, manage, and maintain database applications, no matter which platforms you are using. Toad will grow with you as you investigate and incorporate new technologies in the world of data ensuring freedom of choice today and into the future.
Resources
Toad World is Quest Softwares free online community for anyone working with databases. With more than one million visitors in 2010, it has proven to be your one stop resource for education, expertise, and collaboration. Visit Toad World at www.toadworld.com.
Why Every Java Developer Should Also Know and Use Oracle PL/SQL
14
Why Every Java Developer Should Also Know and Use Oracle PL/SQL
15
TECHNICAL BRIEF
800.306.9329 (United States and Canada) If you are located outside North America, you can find your local office information on our Web site.
E-MAIL MAIL
sales@quest.com Quest Software, Inc. World Headquarters 5 Polaris Way Aliso Viejo, CA 92656 USA
5 Polaris Way, Aliso Viejo, CA 92656 | PHONE 800.306.9329 | WEB www.quest.com | E-MAIL sales@quest.com
If you are located outside North America, you can find local office information on our Web site.
2011 Quest Software, Inc. ALL RIGHTS RESERVED. Quest, Quest Software, the Quest Software logo are registered trademarks of Quest Software, Inc. in the U.S.A. and/or other countries. All other trademarks and registered trademarks are property of their respective owners. TBD_WhyEveryJavaDeveloper_US_VG_20110126