|Oracle® Database Application Developer's Guide - Fundamentals
10g Release 1 (10.1)
Part Number B10795-01
Often, a programming project requires adapting existing code rather than writing new code. When that code comes from some other database platform, it is important to understand the Oracle Database features that are designed to make porting easy.
Topics include the following:
When porting queries from other database systems to Oracle Database, you can code Oracle Database queries using ANSI-compliant notation for joins. For example:
SELECT * FROM a NATURAL JOIN b; SELECT * FROM a JOIN b USING (c1); SELECT * FROM a JOIN b USING (c1) WHERE c2 > 100; SELECT * FROM a NATURAL JOIN b INNER JOIN c;
The standard notation makes the relations between the tables explicit, and saves you from coding equality tests for join conditions in the
WHERE clause. Support for full outer joins also eliminates the need for complex workarounds to do those queries.
Because different vendors support varying amounts of standard join syntax, and some vendors introduce their own syntax extensions, you might still need to rewrite some join queries.
See Oracle Database SQL Reference for full syntax of the
SELECT statement and the support for join notation.
Oracle provides a free product called the Oracle Migration Workbench that can convert a schema (including data, triggers, and stored procedures) from other database products to Oracle Database. Although the product runs on Windows, it can transfer data from databases on other operating systems to Oracle Database running on any operating system.
By using this product, you can avoid having to write your own applications to convert your legacy data when switching to Oracle Database. Related technology lets you convert certain kinds of source code, for example to migrate Visual Basic code to Java.
For the current set of supported databases, see the OTN Web site:
When you want to choose from many different conditions within a query, you can use:
SELECT CASE WHEN day IN ('Monday','Tuesday','Wednesday','Thursday','Friday') THEN 'weekday' WHEN day in ('Saturday','Sunday') THEN 'weekend' ELSE 'unknown day' END FROM DUAL;
This technique helps performance when you can replace a call to a PL/SQL function with a test done directly in SQL.
Oracle Database supports the SQL-92 notation for searched case, simple case,
SELECT DECODE (day, 'Monday', 'weekday', 'Tuesday', 'weekday', 'Wednesday', 'weekday', 'Thursday', 'weekday', 'Friday', 'weekday', 'Saturday', 'weekend', 'Sunday', 'weekend, 'unknown day') INTO day_category FROM DUAL;
This construct lets you test a variable against a number of different alternatives, and return a different value in each case. The final value is used when none of the alternatives is matched.
CASE technique is more portable, and is preferable for new code.