This document summarizes top gotchas or issues with older Oracle database versions, providing examples of outdated syntax or features no longer supported. It covers 20 topics such as using record types for inserts, temporary tables, analytic functions, writing BLOBs to files, and limitations of DBMS_OUTPUT in earlier versions. The document aims to help users of aged Oracle databases avoid problems by being aware of limitations and using alternative approaches as needed.
4. Disclaimer
The following is intended to outline the general product direction
way back in the distant past. It is intended for information purposes
only, and may not always be perfectly syntactically correct. It is not a
commitment to deliver any material, code, or functionality, and
should not be relied upon in making purchasing decisions (if you’re
thinking of buying 8i or 9i, you should probably get out from under
that rock). The development, release, and timing of any features or
functionality described for Oracle’s products remains at the sole
discretion of Oracle… who cares, give us the new features now!
17. #15: DIRECTORY objects
CREATE DIRECTORY mydir AS '/usr/example';
ALTER SYSTEM
SET UTL_FILE_DIR='/usr/example' SCOPE=SPFILE;
- restart database
f := utl_file.fopen( '/usr/example'
, 'myfile.txt'
, 'rw');
18. #14: SQL analytic functions
BEGIN
FOR r IN (
SELECT RANK(a)
OVER (PARTITION BY b
ORDER BY c) q
FROM t) LOOP ...
19. #14: SQL analytic functions
BEGIN
FOR r IN (
SELECT RANK(a)
OVER (PARTITION BY b
ORDER BY c) q
FROM t) LOOP ...
CREATE VIEW v AS
SELECT RANK(a) OVER (PARTITION BY b ORDER BY c) q FROM t;
BEGIN
FOR r IN (SELECT q FROM t) LOOP ...
(alternatively, use dynamic SQL instead)
Analytic functions were added in 8iR2, but they only work in plain SQL – PL/SQL embedded SQL didn’t use the same engine.
R2
26. #10: NULL datatype conversion
SELECT null, null, null
FROM dual
UNION ALL
SELECT 'abc', 123, DATE '2012-01-01'
FROM dual;
ORA-01790: expression must have same datatype as
corresponding expression
?
27. #10: NULL datatype conversion
SELECT null, null, null
FROM dual
UNION ALL
SELECT 'abc', 123, DATE '2012-01-01'
FROM dual;
SELECT null, TO_NUMBER(null), TO_DATE(null)
FROM dual
UNION ALL
SELECT 'abc', 123, DATE '2012-01-01'
FROM dual;
29. #9: MERGE
MERGE INTO d
USING (SELECT * FROM src) s
ON (d.id = s.id)
WHEN MATCHED THEN
UPDATE d.a = s.a, d.b = s.b
WHERE s.a = 'x'
DELETE WHERE s.a = 'z'
WHEN NOT MATCHED THEN
INSERT (s.id, s.a, s.b)
WHERE s.b = 'y';
WHEN MATCHED and WHEN NOT MATCHED are optional*
* DELETE WHERE must be part of a WHEN MATCHED clause, however
30. #9: MERGE
MERGE INTO d
USING (SELECT * FROM src) s
ON (d.id = s.id)
WHEN MATCHED THEN
UPDATE d.a = s.a, d.b = s.b
WHERE s.a = 'x'
DELETE WHERE s.a = 'z'
WHEN NOT MATCHED THEN
INSERT (s.id, s.a, s.b)
WHERE s.b = 'y';
WHEN MATCHED and WHEN NOT MATCHED are mandatory
31. #9: MERGE
MERGE INTO d
USING (SELECT * FROM src) s
ON (d.id = s.id)
WHEN MATCHED THEN
UPDATE d.a = s.a, d.b = s.b
WHEN NOT MATCHED THEN
INSERT (s.id, s.a, s.b);
FOR s IN (SELECT * FROM src) LOOP
UPDATE d SET d.a = s.a, d.b = s.b WHERE d.id = s.id;
IF SQL%ROWCOUNT = 0 THEN
INSERT INTO d VALUES (s.id, s.a, s.b);
END IF;
END LOOP;
32. #8: FORALL on sparse array
FORALL i IN INDICES OF arr
INSERT INTO t (arr(i));
33. #8: FORALL on sparse array
FORALL i IN INDICES OF arr
INSERT INTO t (arr(i));
un-sparse that array, then…
FORALL i IN 1..arr.COUNT
INSERT INTO t (arr(i));
39. #5: Regular Expressions
• Try this homegrown solution:
http://phil-sqltips.blogspot.com.au/2009/06/regexpreplaceregexplike-for-oracle-9i.html
• Or just do it old-school – INSTR, SUBSTR,
LIKE, TRANSLATE, etc.
41. #4: PLS_INTEGER vs. BINARY_INTEGER
• PLS_INTEGER uses native arithmetic = faster
• PLS_INTEGER
- overflow exception
• BINARY_INTEGER overflow
- no overflow exception*
* If a 9i BINARY_INTEGER operation overflows, no exception is raised if the result is being assigned to a NUMBER. In 10g, this is not true –
PLS_INTEGER and BINARY_INTEGER are identical, both raise an exception on overflow.
44. #2, #1, #0
• no PL/SQL conditional compilation
• no Recycle Bin for dropped tables
• no flashback table*
*NOTE: in my original presentation I claimed “no flashback query” in 9i, but this is incorrect.
(Thanks to Tom Kyte for the correction!)
45. Moral of the story?
• Use appropriate
features when available
• Be professional
• Keep old Oracle
documentation URLs