Monday, 30 April 2007

Redo - Part 1

Oracle Redo is oftentimes misunderstood, but most developers and DBAs assume it to mean that in the case of instance failure the database can 'look' here in an attempt to 'redo' operations in a recovery situation.

And they are essentially right. The redo logs are a log of all the changes made to the data. The logs also contain undo information so the data can be 'unwound' to the starting position. What they do not contain is data changes for which we have asked that there be no logging i.e. tables created with NOLOGGING or truncate operations.

But how do we measure our REDO? You can query v$my_stat, see how much redo you generated so far, update or insert a couple of rows, requery and subtract. Nice and simple.

Remember doing row-by-row operations with commits generates a lot more redo than a one-hit SQL statement before commit.

The amount of redo generated for each operation for the same SQL statement varies from release to release.

Friday, 27 April 2007

Converting Between Character Sets

If you have extended characters with accents you can convert them consistently and safely as follows:

SELECT CONVERT ('ediária', 'US7ASCII', 'WE8ISO8859P1') AS converted 
FROM DUAL;

ediaria


Consistent and already available for you to use.

Number to Words Conversion

This is something useful only as a trick or a quick hack.

How do you get from a number to the same number spelled out in words.

Here is something that works perfectly well but was not intended to be used in the way this example shows. It is a mistreatment of the to_char function based on a manipulating a date for output.

SELECT n, TO_CHAR (DATE '-4712-01-01' + (n - 1), 'jspth')
FROM (SELECT 1721058 n
FROM DUAL);

one million seven hundred twenty-one thousand fifty-eighth


So it does work - just don't rely on it - it is after all a to_char on a date field.