Saturday, November 20, 2010

Oracle Redo log file size

I was trying to delete a number of rows (1-2M) from a table on the new production server last night and found the operation was taking far too long. Although there are delete optimization techniques, like using temp tables, it certainly wasn't anywhere near enough records to have to implement something like that.

A little digging showed that the operation was blocking on "log file switch (checkpoint incomplete)". Resizing the log files did the trick.

Oracle PL/SQL: ISBN10 Validator

Another little function to make sure you've got a valid ISBN10 before you attempt to convert it.
create or replace
FUNCTION "VALIDATE_ISBN10" (
ISBN10 IN VARCHAR2
) RETURN NUMBER IS

v_checksum NUMBER := 0;
v_digit NUMBER := 0;
v_pos NUMBER := 1;
v_rem NUMBER;

BEGIN
IF (LENGTH(ISBN10) != 10)
THEN RETURN 0;
END IF;

WHILE (v_pos <= 9) LOOP
v_digit := substr(ISBN10,(v_pos),1);
v_checksum := v_checksum + (v_pos * v_digit);
v_pos := v_pos + 1;
END LOOP;
v_rem := mod(v_checksum,11);

IF (v_rem = 10 AND 'X' = substr(ISBN10,10,1))
THEN RETURN 1;
END IF;

IF (v_rem < 10 AND TO_NUMBER(substr(ISBN10,10,1)) = v_rem)
THEN RETURN 1;
END IF;

return 0;
exception when value_error then
return 0;
END VALIDATE_ISBN10;

Oracle PL/SQL: Convert ISBN10 to ISBN13 (EAN)

Wrote this because of vendors that still are using ISBN10. Not as optimized as it could be... But should get the job done.

create or replace
FUNCTION "ISBN10TO13" (
ISBN10 IN VARCHAR2
) RETURN VARCHAR2 IS

v_isbntemp VARCHAR2(13) := '';
v_isbn13 VARCHAR2(26) := '';
v_checksum NUMBER := 0;
v_digit NUMBER := 0;
v_pos NUMBER := 1;

BEGIN
v_isbntemp := '978' || substr(ISBN10,0,9);

WHILE (v_pos <= 12) LOOP
v_digit := substr(v_isbntemp,(v_pos),1);
IF (MOD(v_pos,2) = 0)
THEN v_checksum := v_checksum + (v_digit * 3);
ELSE v_checksum := v_checksum + (v_digit * 1);
END IF;
v_pos := v_pos + 1;
END LOOP;

v_checksum := 10 - MOD(v_checksum,10);
IF (v_checksum = 10)
THEN v_checksum := 0;
END IF;

v_isbn13 := v_isbntemp || v_checksum;

RETURN v_isbn13;
END ISBN10TO13;