Old Oracle Versions

1,573 views

Published on

Published in: Technology, News & Politics
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,573
On SlideShare
0
From Embeds
0
Number of Embeds
6
Actions
Shares
0
Downloads
15
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Old Oracle Versions

  1. 1. Old Oracle Versions Top 20 Gotchas Jeffrey Kemp AUSOUG Perth Conference, October 2012
  2. 2. Poll • Oldest Oracle database version worked with • Past 12 months (approximately)
  3. 3. Database Versions & Extended Support v7 v8 8i 9i 9iR2 10g 10gR2 11g 11gR2 2015 2010 2005 2000 1995 1992 12c
  4. 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!
  5. 5. “Be grateful for what you have...”
  6. 6. vs.
  7. 7. #20: insert from record type INSERT INTO mytable VALUES rec;
  8. 8. #20: insert from record type INSERT INTO mytable VALUES rec; INSERT INTO mytable (col1, col2, col3, …) VALUES (rec.col1, rec.col2, rec.col3, …);
  9. 9. #19: temporary tables CREATE GLOBAL TEMPORARY TABLE t...
  10. 10. #19: temporary tables BEGIN TRUNCATE TABLE ordinary_tmp; INSERT INTO ordinary_tmp ...; -- etc… END;
  11. 11. #18: error messages EXCEPTION DBMS_OUTPUT.put_line( DBMS_UTILITY.format_error_backtrace ); RAISE; END;
  12. 12. #18: error messages EXCEPTION DBMS_OUTPUT.put_line( DBMS_UTILITY.format_error_backtrace SQLERRM ); RAISE; END;
  13. 13. #17: queries on DBMS_RANDOM SELECT DBMS_RANDOM.value FROM dual; ORA-00600 internal error http://www.angelfire.com/home/jasonvogel/oracle_plsql_random_number_generator.html
  14. 14. #16: TIMESTAMP & INTERVAL the_exact_time TIMESTAMP := SYSTIMESTAMP;
  15. 15. #16: TIMESTAMP & INTERVAL the_exact_time TIMESTAMP := SYSTIMESTAMP; Java - timestamp.getTime() (number of milliseconds since January 1, 1970, 00:00:00 GMT)
  16. 16. #15: DIRECTORY objects CREATE DIRECTORY mydir AS '/usr/example';
  17. 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. 18. #14: SQL analytic functions BEGIN FOR r IN ( SELECT RANK(a) OVER (PARTITION BY b ORDER BY c) q FROM t) LOOP ...
  19. 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
  20. 20. #13: write BLOB to file l_file := UTL_FILE.fopen ('BLOBS','MyImage.gif','w', 32767); WHILE l_pos < l_blob_len LOOP DBMS_LOB.read(l_blob, l_amount, l_pos, l_buffer); UTL_FILE.put_raw(l_file, l_buffer, TRUE); l_pos := l_pos + l_amount; END LOOP; UTL_FILE.fclose(l_file);
  21. 21. #13: write BLOB to file l_file := UTL_FILE.fopen ('BLOBS','MyImage.gif','w', 32767); WHILE l_pos < l_blob_len LOOP DBMS_LOB.read(l_blob, l_amount, l_pos, l_buffer); UTL_FILE.put_raw(l_file, l_buffer, TRUE); l_pos := l_pos + l_amount; END LOOP; UTL_FILE.fclose(l_file); Java - http://www.oracle-base.com/articles/8i/export-blob.php
  22. 22. #12: external tables CREATE TABLE t ... ORGANIZATION EXTERNAL
  23. 23. #12: external tables CREATE TABLE t ... ORGANIZATION EXTERNAL CREATE OR REPLACE VIEW diy$extfile AS SELECT * FROM TABLE( CAST(read_file_into_array() AS my_array_type) ); (using UTL_FILE) - http://www.oracle-base.com/articles/8i/diydynamic-views.php
  24. 24. #11: XMLTYPE CREATE TABLE t (myxml XMLTYPE);
  25. 25. #11: XMLTYPE CREATE TABLE t (myxml XMLTYPE); xmlparser.parse( v_parser , 'C:emp.xml'); v_doc := xmlparser.getDocument (v_parser); http://www.oracle-base.com/articles/8i/parsexml-documents-8i.php
  26. 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. 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;
  28. 28. vs.
  29. 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. 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. 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. 32. #8: FORALL on sparse array FORALL i IN INDICES OF arr INSERT INTO t (arr(i));
  33. 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));
  34. 34. #7: UTL_MAIL
  35. 35. #7: UTL_SMTP
  36. 36. #6: string literals v_sql := q'[SELECT q'{She said 'Hello'.}' FROM t]';
  37. 37. #6: string literals v_sql := q'[SELECT q'{She said 'Hello'.}' FROM t]'; single-quotes-masquerading-as-double-quotes hell… v_sql := 'SELECT ''She said ''''Hello''''.'' FROM t';
  38. 38. #5: Regular Expressions • REGEXP_INSTR • REGEXP_REPLACE • REGEXP_SUBSTR
  39. 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.
  40. 40. #4: PLS_INTEGER vs. BINARY_INTEGER PLS_INTEGER = BINARY_INTEGER
  41. 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.
  42. 42. #3: DBMS_OUTPUT Max size: unlimited Line size: 32KB
  43. 43. #3: DBMS_OUTPUT Max size: 1 million bytes* Line size: 255 bytes *default = 20,000 bytes
  44. 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. 45. Moral of the story? • Use appropriate features when available • Be professional • Keep old Oracle documentation URLs
  46. 46. Images Attribution http://4.bp.blogspot.com/-ib6RKHzuEaU/Tb4aaXaqYI/AAAAAAAANVk/s5RPjflt4hU/s1600/cadillac-car-wreck.jpg http://images.brisbanetimes.com.au/2012/03/08/3109605/Women%20vote.jpg http://i47.photobucket.com/albums/f189/captjeremy/ace_ventura_pet_detective_fake _pict.jpg http://rlv.zcache.com/vintage_business_mailman_mail_carrier_delivering_postcardp239921576489667584envli_400.jpg http://technology.amis.nl/2006/04/04/back-to-the-future-oracle-41-vm-appliance/
  47. 47. Thank you http://jeffkemponoracle.com

×