Добавил:
Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Скачиваний:
32
Добавлен:
16.04.2013
Размер:
4.96 Mб
Скачать

14

Porting Non-Oracle Applications to Oracle Database 10g

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:

Performing Natural Joins and Inner Joins

Migrating a Schema and Data from Another Database System

Performing Several Comparisons within a Query

Porting Non-Oracle Applications to Oracle Database 10g 14-1

Performing Natural Joins and Inner Joins

Performing Natural Joins and Inner Joins

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.

Migrating a Schema and Data from Another Database System

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:

http://otn.oracle.com/

Performing Several Comparisons within a Query

When you want to choose from many different conditions within a query, you can use:

14-2 Oracle Database Application Developer's Guide - Fundamentals

Performing Several Comparisons within a Query

The SQL statement CASE:

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,

NULLIF, and COALESCE.

The SQL function DECODE:

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.

The CASE technique is more portable, and is preferable for new code.

Porting Non-Oracle Applications to Oracle Database 10g 14-3

Performing Several Comparisons within a Query

14-4 Oracle Database Application Developer's Guide - Fundamentals

Тут вы можете оставить комментарий к выбранному абзацу или сообщить об ошибке.

Оставленные комментарии видны всем.

Соседние файлы в папке Oracle 10g