Database Journal
MS SQL Oracle DB2 Access MySQL PostgreSQL Sybase PHP SQL Etc SQL Scripts & Samples Links Database Forum

» Database Journal Home
» Database Articles
» Database Tutorials
MS SQL
Oracle
DB2
MS Access
MySQL
» RESOURCES
Database Tools
SQL Scripts & Samples
Links
» Database Forum
» Sitemap
Free Newsletters:
DatabaseDaily  
News Via RSS Feed


follow us on Twitter
Database Journal |DBA Support |SQLCourse |SQLCourse2
 

Featured Database Articles

Oracle

Posted Jul 27, 2005

Strong SQL Made Even Stronger: Oracle 10g SQL Enhancements, Part 1

By Jim Czuprynski

Synopsis. Oracle 10g extends many of the already robust features of Structured Query Language (SQL). This article the first of a series illustrates some of the more intriguing new features of SQL within Oracle, including upgrades to the MERGE command, enhancements to hierarchical query capabilities, and improvements to query and access methods for nested tables.

As a DBA and as an applications developer, I have worked with DB2, Teradata, Informix, Sybase, and SQLServer databases. I have to admit that Oracle's extensions to standard ANSI Structured Query Language (SQL) have always impressed me as some of the most powerful query and data maintenance tools in the industry. Since I spend a lot of time writing, reviewing, and testing SQL statements for efficiency and elegance, I always get excited when Oracle makes that part of my job easier.

Oracle has made some impressive improvements to this already-robust suite of extensions in Oracle 10g, and I will cover some of the more significant ones in this next series of articles, starting with one of my personal favorites, the MERGE command.

Data Traffic, MERGE Right: MERGE Command Syntax Upgrades

I was thrilled when Oracle 9i introduced the MERGE statement because it acknowledged that there is a constant need to either include new data or update existing information from a common data source, but on a conditional basis. As a recycled mainframe programmer whose first programming experience was with a now almost-defunct 4GL language called FOCUS, I still remember its most powerful feature for updating databases: the MODIFY command, which offered the ability to either create a new entry or update an existing entry in a database table based on a simple set of conditional tests against matching transaction and database values.

The Oracle 9i version of MERGE offered the ability to either insert new rows or update existing values in a table based on matching conditions. Oracle 10g has enhanced the MERGE statement even further: it now allows execution of a combination of INSERT, UPDATE, and DELETE DML commands within one PL/SQL block. This makes for extremely versatile code structures. I will illustrate this new versatility using the following scenario:

The investment management firm that manages your client's retirement benefits program has provided an Excel spreadsheet that lists all employees that have recently either:

  • joined the 401(k) retirement benefits program
  • made a contribution to their 401(k) accounts since the last file was received
  • terminated their involvement in their 401(k) plans

The Human Resources department has asked this information be applied immediately to the appropriate database tables so that they can determine if there is a downturn in employee participation in the 401(k) retirement program.

To handle this request, I will convert the incoming Excel spreadsheet to a comma-separated values (CSV) file and then create an external table to read the CSV file. Using the enhanced MERGE command, I will then apply those transaction data against the table that contains the status of every employee's participation in the company's 401(k) program.

Listing 1.1 shows the transaction table, the external table definition, and the MERGE statement that illustrate this solution.



Oracle Archives

Comment and Contribute

 


(Maximum characters: 1200). You have characters left.

 

 




Latest Forum Threads
Oracle Forum
Topic By Replies Updated
Oracle Data Mining: Classification jan.hasller 0 July 5th, 07:19 AM
Find duplicates - Unique IDs Lava 5 July 2nd, 08:30 AM
no matching unique or primary key rcanter 1 April 25th, 12:32 PM
Update values of one table based on condition of values in other table using Trigger Gladiator 3 February 29th, 06:01 PM


















Thanks for your registration, follow us on our social networks to keep up-to-date