2007-09-13

How to port SQL Server OPENXML to Oracle PL/SQL



If you want to port code that contain OPENXML calls from SQL Server to Oracle, you will find that there is no such call. OPENXML works with sp_xml_preparedocument and xp_xml_removedocument calls to produce (among other things) a relational table based on XML document.



In my case, I use the XML document to pass an array of primary keys, use them as a filter for a table and join and return them.



For example suppose an application based on SQL Server TSQL has:

A table "BRANDS" contain a BRAND_ID (INT) and a TITLE (VARCHAR)

such as:

BRAND_ID TITLE

1 Nokia

2 Siemens

3 Other

4 IBM

5 HP



A stored procedure GET_BRAND_LIST as:

CREATE PROCEDURE dbo.GET_BRAND_LIST(@IDLIST NTEXT )

AS

DECLARE @hDoc int

EXEC sp_xml_preparedocument @hDoc OUTPUT, @IDLIST


SELECT BRAND_ID, TITLE FROM BRANDS

INNER JOIN OPENXML (@hDoc, '/s/k',2) WITH (I int) AS ResultSet

ON BRANDS.BRAND_ID = ResultSet.I



EXEC sp_xml_removedocument @hDoc

RETURN



GO



And an XML input similar to:


where:



  • s is the root element



  • k specifies a primary key and



  • I the value of the primary key

such as:




calling GET_BRAND_LIST will return the brands with BRAND_ID equal to 1, 3 and 4.





Here is how to do the same in Oracle:






  • Use CBLOB instead on NTEXT to pass the XML value.



  • Use XMLType instead on sp_xml_preparedocument and sp_xml_removedocument calls.



  • Use XMLSequence to convert and create a temporary table filled with the primary keys.



  • Use EXTRACT to get the primary key value to perform the Join.

The complete Oracle code:
PROCEDURE GET_BRAND_LIST (cur_OUT OUT T_CURSOR, pIDLIST CLOB)
IS
anXmlType XmlType;
V_CURSOR T_CURSOR;
BEGIN
anXmlType := XmlType(pIDLIST);
OPEN V_CURSOR FOR
SELECT BRANDS.BRAND_ID, BRANDS.TITLE
FROM BRANDS,
table(XMLSequence(extract(anXMLType, '/s/k/*'))) ResultSet
WHERE BRANDS.BRAND_ID = TO_NUMBER(EXTRACT(value(ResultSet), 'I/text()'));



cur_OUT := V_CURSOR;
END;


2006-05-30

The Antikythera Mechanism Research Project

The Antikythera Mechanism is an ancient astronomical computer built by the Greeks around 80 B.C. It was found on a shipwreck by sponge divers in 1900, and its exact function still eludes scholars to this day.

2006-05-22

Game Innovation Database.

Do you remember "Shadow of the Beast"? Lemmings? probably YES...If you are a fan of computer games.

Well, GIdb goal is to classify and record every innovation in the entire history of computer and videogames.

2006-05-17

Five Years of Design

Martin Fowler writes about the articles of the past five years of IEEE Software “Design” section, before passing the editing of the section to Rebecca Wirfs-Brock. This last article explains the basic Design Principles, the derived Best-Practices and their role in the software development process.

Thanks Martin.

2006-05-16

Development (Print) magazines are disappearing…

CMP Media has recently “merge” two of the most known software development magazines; Software Development and the C++ Users Journal (one of the last magazines dedicated to C/C+) into Dr. Dobbs magazine. Fortunately, I have an active subscription to Dr. Dobbs and I won’t lose any subscription fees.
Several years ago, CMP has also ceased the publication of the “legendary” BYTE magazine which makes me very angry (back in 1998) because a valuable source of information has been lost.

Obviously big publishing companies began to realize the importance of getting all the information directly from the provider using its blog, from a Usenet forum, or from a web site found be Google Search, and they make major efforts to create software development portals to replace the gap.

The difference is obvious.

2006-01-04

A Brief Look at C++0x

Bjarne offers a sneak peek at the next version of standard C++ ("C++0x") which should be complete by 2009.

2005-05-05

Do you know Al-Khowarizmi?

According to Knuth (you should know Knuth), the word "Algorithm" is derived from the name Al-khowarizmi, a ninth-century Persian mathematician.


2005-01-13

Embrace change.

Are you trying to learn new things constantly?
Do you embrace change in your life?

2005-01-05

Computer History Museum

On April 7 of 1969, Steve Crocker sends around a memo entitled ‘Request for Comments.’ This is the first of thousands of RFCs that document the design of the ARPANET and the Internet.

2004-07-08

Computer Pioneer Bob Bemer Passes Away

Who was Bob Bemer:
* the 'father or ASCII' character set.
* the 'grandfather' of COBOL.
* the inventor of ESCAPE and BACKSLASH sequences.
* the man behind the '8-bit' byte standardization.
* a pioneer in 3-D dynamic prespective.

Bob Bemer was awarded by IEEE Computer Society with the Computer Pioneer Award.

2004-06-07

Do you remember this machines?

The fundamental parts of software today, remains the same as LISA or NextStep software written 25 years ago, with a complete GUI metaphor, a true pre-emptive multitasking operating system, productivity applications an a true object oriented development environment.

2004-06-03

Visual C++ 2005

Microsoft Visual C++ returns as mainstream programming language with the next release of Visual Studio. Microsoft enhances the runtime libraries, the STL and adds language constructs for .NET compatibility.

2004-05-20

OO in One Sentence

Keep it DRY, Keep it Shy, and Tell the Other Guy..

Here is the original paper from Andy Hunt and Dave Thomas.

2004-05-19

Operational - Reporting Databases

Martin Fowler's - Reporting Database

The separation of reporting database from the operational database provides unique advantages such as: data from business logic (calculated), a de-normalized view of database (fewer joins), maintainability of operational database and runtime performance (fewer locks)

See also:
* Martin Fowler Bliki
* Reporting from Database

2004-05-17

Favorite links

Allen Bauer, Borland Delphi and C#Builder IDE Architect(http://homepages.borland.com/abauer/index.html)

Don Box's Spoutlet (http://www.gotdotnet.com/team/dbox/default.aspx)

Charlie Calvert (http://homepages.borland.com/ccalvert/index.htm)

Danny Thorpe, Delphi Compiler Architect (http://homepages.borland.com/dthorpe/blog/delphi/)

Steve Vinoski's Weblog (http://www.iona.com/blogs/vinoski/)

2004-05-16

Hallmarks of a Good Design Review

* The reviewers are looking for issues in the design not on the designer.

* The reviewers and the designer should have the right attitude.

* A design engineer should accept criticism of his ideas and proposals by the reviewers.

* Distribute related artifacts to all reviewers before the actual review.

The Principles of Lean Software Development

Eliminate waste by removing anything that does not add value - Create teams of people with specific responsibilities to enhance value.

Amplify learning by increasing feedback – Create weekly to monthly, full cycle iterations.

Keep your options open – Share, Organize direct collaboration, Absorb changes, Refactor, Automate test.

Deliver Fast – Enable a smooth, rapid flow in response to customer needs.

Empower the Team – Train the team to design its own process and make commitments.

Conceptual and Perceived Integrity – Test early, test often, test exhaustively and use an automated test suite.