views:

466

answers:

1

Hi, I was wondering if there are any good refactoring tools for Oracle databases and especially for PL/SQL. I'm working on a project where half the developers are working with c# and the other half on the db where there is a large and complex schema and a large code base in pl/sql. We also use sql server but the database team work exclusively with Oracle.

This code base is being worked on actively and is being refactored gradually but I was quite surprised to see how bad the refactoring tools for oracle seem to be (or at least in comparison to Eclipse and Resharper).

The developers are using Toad which only has basic refactoring support (probably as its seems to be targeted more towards db admin then development). I've used Toad myself before but always had assumed for pl/sql there were more features for working with code but had never looked into it. Now as far as I can see the only refactorings that it provides are extract method (procedure) and variable renaming. I read an article comparing sql developer and pl/sql developer and these do not appear to have any better support for refactoring. I had a quick look at the eclipse data tools project but couldn't see that they've added refactoring support since I last used it (a few years ago).

For Sql Server there exists Sql Refactor which when table structures are changed gets propagated through to the stored procedures. This for me is much cleaner and less error prone than having someone manually update all stored procedures. I used an older version of these tools on a project in the past and they seemed to be quite ok but a bit slow but that was a few years ago and it was still usable.

Something similar for Oracle would already be a big help for our developement team so I'd appreciate some pointers to good refactoring tools for Oracle if they do exist. Thanks, Crocked

+3  A: 

As it happens the "D" in TOAD stands Developer not DBA. In fact many DBAs anathematise TOAD and other such tools.

You are out of luck. As far as I know there are no tools for refactoring PL/SQL. The root problem is that refactoring as a concept comes from the OOP paradigm, and PL/SQL is not object oriented. It does not support inheritance or polymorphism (*). This means that many of the techniques which underpin classical refactoring practice (say as defined by Fowler) - abstraction, interfaces, etc - have no analogue in PL/SQL.

The corollary of this is that people who are used to having refactoring as part of their conceptual toolbox tend to avoid programming with PL/SQL. I once got into a heated debate on the TDD list over this. The upshot being that even developers who need and appreciated the virtues of PL/SQL would rather develop in languages with better tool support, clause #1 of the Agile Manifesto notwithstanding.

The most important tool for refactoring is automated unit testing. Although TOAD does not (I think) have integrated unit testing, the next release of Oracle SQL Developer will. There are also standalone unit test tools. I recently mentioned a couple of them in another SO thread.

In terms of refactoring PL/SQL to match changes in the database, arguably most interaction with tables ought to be underaqtken by generated table APIs rather than being embedded in transactional PL/SQL. In this happy realm there is no need for refactoring tools, we just need to re-generate the relevant APIs. The post I linked to above also mentions QCGU, a tool which can do this. Of course, when we have a PL/SQL codebase which isn't organised in such a fashion then life is harder. You won't be surprised to learn that there isn't a lot of tool support for implementing Feathers's WELC in PL/SQL.

(*) Yes, I know Oracle has Types but they are (a) SQL not PL/SQL and (b) how many people out there are actually building APIs using them?

APC
+1 for the comprehensive answer. Where you say: "arguably most interaction with tables ought to be underaqtken by generated table APIs rather than being embedded in transactional PL/SQL." do you have any links\resources you can point me to on this subject?
carpenteri
As with most things PL/SQL, Steven Feuerstein is the goto man. In this case his presentation Break Your Addiction To SQL is the place to start. Try to catch it a conference (he's a great presenter) Unfortunately the internet doesn't seem to have a copy of it, but his Best Practices stuff mentions it a lot: http://www.toadworld.com/Education/StevenFeuersteinsPLSQLExperience/Trainingandpresentations/tabid/155/Default.aspx ... Also Toon Koppleaars blog is very good on the topic of building PL/SQL APIs : thehelsinkideclaration.blogspot.com
APC
Thanks for getting back to me so quick with the links etc - I agree regarding Steven Feuerstein presenting skills - Saw my first presentation of his on 9/11! Hoping I can be spared from work so I can attend the UKOUG on the 30th and see both him and Tom on the same day. Thanks again
carpenteri
Tom Kyte and Steven Feuerstein are at daggers drawn (well, almost) over the benefits or not of table APIs: http://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:672724700346558185
Tony Andrews
@Tony - I kinew Tom and Steven disagreed over this but I had missed that actual link. As it happens over the recent years I haved worked mainly with Transactional APIs and not much with Table APIs. But I think TAPIs - at least in the form of a view for every table - are going to become fashionable again, due to 11gR2's Edition-Based Redefinition feature
APC
@Tony - Thanks for a very interesting link
carpenteri