Mohamed Houri’s Oracle Notes

June 25, 2008

Getting differences between two tables

Filed under: Oracle — hourim @ 3:45 pm

When we upgrade applications from Mainframe/UNISYS to ORACLE/SUN environment we need to ensure a perfect synchronization between the new application and the migrated one. In order to achieve this goal, one solution would be to put the content of the Mainframe application into a dedicated table, let’s say mainframe_tab for example. The initial load starts by loading via a sqlloader a flat file into the mainframe_tab table and then it triggers the process of the initial load into the new application. Within the new application very often the migrated data are mapped into new typologies and are changed so that it reflects the new philosophy of a relational data base. Each record “initially loaded” must end by an insert of the same record (get again from the new application) into a clone table to the mainframe_tab; let’s call it the oraclesun_tab.  At the end of the initial load we will have at our disposable two tables full of the same data (normally the same data, this why we want to synchronize them). Hence one important step in this synchronization is to find the differences that might exist into these two cloned tables. Here below is a demo on how to find those differences. Thanks a lot to Tom Kyte for his help in this case

 

</p>

<pre>CREATE TABLE mainframe_tab
(ide NUMBER,
 appl VARCHAR2(3),
 x NUMBER,
 y NUMBER,
 w VARCHAR2(15),
 z VARCHAR2(30)
);

create table oraclesun_tab
( ide number,
 appl varchar2(3),
 x number,
 y number,
 w varchar2(15),
 z varchar2(30)
);

insert into mainframe_tab ( ide, appl, x, y, w, z ) values (
4, ‘SPS’, 23, 13, ‘Lieven’, ‘Ali’);

insert into mainframe_tab ( ide, appl, x, y, w, z ) values (
3, ‘SPS’, 17, 31, ‘Desire’, ‘Omar’);

insert into mainframe_tab ( ide, appl, x, y, w, z ) values (
2, ‘SPS’, 11, 155.2, ‘Tom’, ‘Asif’);

insert into mainframe_tab ( ide, appl, x, y, w, z ) values (
1, ‘SPS’, 125, 13.2, ‘Richard’, ‘Jean’);

insert into oraclesun_tab ( ide, appl, x, y, w, z ) values (
4, ‘CCO’, 23, 13, ‘Lieven’, ‘Ali’);

insert into oraclesun_tab ( ide, appl, x, y, w, z ) values (
3, ‘CCO’, 17, null, ‘Desire’, ‘Omar’);

insert into oraclesun_tab ( ide, appl, x, y, w, z ) values (
2, ‘CCO’, 11, 155.2, ‘Tom’, ‘Asif’);

insert into oraclesun_tab ( ide, appl, x, y, w, z ) values (
1, ‘CCO’, 125, 13.2, ‘Richard’, ‘Jean-Pol’);

commit;

Now we would like to get the differences between these two tables for each ide. Of course the application name (SPS for SUN and CCO for mainframe) should not be considered as a difference. This is the select to issue

 

<pre>SELECT ide, x, y, z, w, count(src1), count(src2),
 decode (min (appl_1), NULL, min (appl_2), min (appl_1))
 FROM (SELECT t1.*, 1 src1, to_number (NULL) src2, appl appl_1,
 NULL appl_2
 FROM oraclesun_tab t1
 UNION ALL
 SELECT t2.*, to_number (NULL) src1, 2 src2, NULL appl_1,
 appl appl_2
 FROM mainframe_tab t2 )
GROUP BY ide, x, y, z, w
HAVING count (src1) <> count (src2);

Ide

Application

x

y

z

w

1

SPS

125,00

13,20

Jean

Richard

1

CCO

125,00

13,20

Jean-Pol

Richard

3

SPS

17,00

31,00

Omar

Desire

3

CCO

17,00

 

Omar

Desire

June 13, 2008

Oracle Forms Compilation

Filed under: Oracle — hourim @ 2:26 pm

Here it is a small script (but how useful is it when we need to re-compile a high number of oracle forms 6i during the release management process).  You have to create a *.bat file in which you will include the following code:

Rem Batch used to recompile oracle forms
Rem Oracle Forms compilation start

cd C:\Forms\Src\
FOR%%A in(*.fmb)DO D:\orant\bin\ifcmp60.exe module=%%A userid=scott/tigger@orcl batch=YES
echo compilation successfully finished
pause;

June 10, 2008

When Other Then Exception

Filed under: Oracle — hourim @ 10:47 am

I have just posted a comment on this thread about what Tom Kyte consider as 99.99999999% a bug. I was wondering if, the following plsql code which I very often use when loading data bases, represents also a bug. A typical example is when we want to “initial load” a huge amount of client information. The requirements are:

  • Do not stop the initial load in case of error occurring during the treatment of one record (client information)
  • Log each record as “Successful” or “Not Successful with its corresponding Error”
  • Make your process restartable
  • Do not commit across fetch in order to avoid ORA-01555 rollback segment snapshot too old error
  • In order to fulfil these requirements, I came always to such a kind of plsql code

BEGIN
FOR r_client in c_client LOOP
BEGIN
-- set a savepoint here
savepoint sps_a_savep;
-- Create/Update/Delete or Do here what ever your want in order requirements
-- to achieve you requirements
-- Update successfull record
UPDATEclient
SET treated_record ='Y';
WHERE client_record = r_client.client_id;

EXCEPTION
WHEN OTHERS THEN
-- Here there is a when other exception which is not followed by a RAISE

ROLLBACKTO sps_a_savep;
-- Update Unsuccessfull record with its error
     UPDATE  client
     SET treated_record ='N';
      error_code        =SQLERRM
      WHERE client_record = r_client.client_id;
END;
-- Treat next record
END LOOP;
-- Commit outside the loop in order to avoid ORA-01555
COMMIT;

EXCEPTION
WHEN OTHERS THEN
 ROLLBACK;
 RAISE;   -- it is here were I want also to make a comment(see below)
END;

Hopefully this case it one of 0.0000001 cases for which the WHEN OTHER EXCEPTION not followed by a RAISE is not a bug. But now I understand why Tom Kyte is always saying that it had better for the WHEN OTHER EXCEPTION that ORACLE has not created it. Because even if we use it and we use the RAISE command we will lose the exact plsql line number which really causes the exception to be raised.

Blog at WordPress.com.

Tony's Oracle Tips

Tony Hasler's light hearted approach to learning about Oracle

Richard Foote's Oracle Blog

Focusing Specifically On Oracle Indexes, Database Administration and Some Great Music

Hatem Mahmoud's blog

Just another blog : Databases, Linux and other stuffs

Mohamed Houri’s Oracle Notes

Qui se conçoit bien s’énonce clairement

Oracle Diagnostician

Performance troubleshooting as exact science

Raheel's Blog

Things I have learnt as Oracle DBA

Coskan's Approach to Oracle

What I learned about Oracle

So Many Oracle Manuals, So Little Time

“Books to the ceiling, Books to the sky, My pile of books is a mile high. How I love them! How I need them! I'll have a long beard by the time I read them”—Lobel, Arnold. Whiskers and Rhymes. William Morrow & Co, 1988.

Carlos Sierra's Tools and Tips

Tools and Tips for Oracle Performance and SQL Tuning

Oracle Scratchpad

Just another Oracle weblog

OraStory

Dominic Brooks on Oracle Performance, Tuning, Data Quality & Sensible Design ... (Now with added Sets Appeal)