LOBS, BLOBS, CLOBS: Dealing with Attachments in APEX

2,765 views
2,446 views

Published on

Published in: Technology
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
2,765
On SlideShare
0
From Embeds
0
Number of Embeds
3
Actions
Shares
0
Downloads
43
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

LOBS, BLOBS, CLOBS: Dealing with Attachments in APEX

  1. 1. @sthilaire wphilltech.com LOBS, BLOBS, CLOBS Dealing with Attachments in APEX Tim St. Hilaire Feb 2014
  2. 2. @sthilaire wphilltech.com The Plan • • • • • • • Intro The Goal APEX BLOB Wizard Making It Your Own Base Technology Advanced Database Concepts Questions
  3. 3. @sthilaire wphilltech.com Introduction Tim St. Hilaire • System Integrator • Problems Solver • Pragmatist • Technology Enthusiast • APEX Fan • Enkitec Product Developer
  4. 4. @sthilaire wphilltech.com The Goal • Ability to accept file attachment input from users in an application • Use the content in applications either as text, images, or downloadable to users • Understand how the data is stored, retrieved, and managed inside the database
  5. 5. @sthilaire wphilltech.com Demonstration – The Goal
  6. 6. @sthilaire wphilltech.com The Academics
  7. 7. @sthilaire wphilltech.com The Academics • LOB – Large Objects – broken down into datatypes – BLOB - Stores unstructured binary data in the database as a bit stream – CLOB – Stores large amounts of text such as XML in the database character set – NCLOB – National Character Set LOB – stores Unicode data – BFILE – external LOB – Secure File LOB – file data enabling advanced features such as compression and encryption
  8. 8. @sthilaire wphilltech.com BLOB vs. CLOB • BLOB – Stream of data intended to be binary – Chunks are returned in RAW format (substr) • CLOB – Will translate between character sets – Chunks are returned in VARCHAR2 format (substr) SELECT * FROM NLS_DATABASE_PARAMETERS WHERE PARAMETER = 'NLS_CHARACTERSET';
  9. 9. @sthilaire wphilltech.com There are 10 types of people in the world… Those that understand binary, and those that don’t. -- The Internet
  10. 10. @sthilaire wphilltech.com APEX
  11. 11. @sthilaire wphilltech.com Demonstration - APEX Submit Button
  12. 12. @sthilaire wphilltech.com Where did the file go? WWV_FLOW_FILES APEX_APPLICATION_FILES
  13. 13. @sthilaire wphilltech.com Table Context Sensitivity • APEX_APPLICATION_FILES – limits to files available in the workspace. • Includes files that were uploaded by all applications in a workspace • Includes files that have been uploaded via the builder • Includes Static Shared Component Files for the Application and the Workspace
  14. 14. @sthilaire wphilltech.com Evaluate WWV_FLOW_FILES Pros • No Table Creations Required • Consistent Implementation • Storage in a known location Cons • Need Remote Key Storage • Application Files combined • Storage for all Workspaces is shared • Some Files are publicly available
  15. 15. @sthilaire wphilltech.com Custom Table
  16. 16. @sthilaire wphilltech.com My Table • To configure your own table • Minimum Requirements • Adjust to Features and Business Requirements ID ACTUAL_FILE MIME_TYPE FILE_NAME NUMBER (your choice) BLOB VARCHAR2 VARCHAR2
  17. 17. @sthilaire wphilltech.com Custom Table CREATE TABLE MY_APEX_FILES( BLOB_ID NUMBER NOT NULL, NAME VARCHAR2(100 BYTE), DESCRIPTION VARCHAR2(2000 BYTE), CATEGORY VARCHAR2(200 BYTE), PUBLIC_FLAG VARCHAR2(1 BYTE), BLOB_CONTENT BLOB, BLOB_SIZE NUMBER, MIME_TYPE VARCHAR2(255 BYTE), FILE_NAME VARCHAR2(255 BYTE), CREATED_BY VARCHAR2(50 BYTE), CREATED_ON DATE, UPDATED_BY VARCHAR2(50 BYTE), UPDATED_ON DATE);
  18. 18. @sthilaire wphilltech.com Referencing
  19. 19. @sthilaire wphilltech.com Form - File Browse Settings
  20. 20. @sthilaire wphilltech.com Form - Display Images
  21. 21. @sthilaire wphilltech.com Form - Display Images
  22. 22. @sthilaire wphilltech.com Form - Display Images
  23. 23. @sthilaire wphilltech.com Form - Display Images
  24. 24. @sthilaire wphilltech.com Form - Display Images
  25. 25. @sthilaire wphilltech.com Form - Difference <img id="P210_IMAGE" src="apex_util.get_blob_file ?a=500&amp;s=9700348909 98301&amp;p=210&amp;d= 27553826455759041&amp;i =27566106354076381&amp ;p_pk1=3212306414813867 83828770868593367722825 &amp;p_pk2=&amp;p_ck=D 164075B30411E1CF29B6B9 ED9A57684" alt="Hunger" title="Hunger"> <img id="P210_IMAGE_SELECT" src="wwv_flow.show?p_req uest=NATIVE%3DC825C6CF6 97537EC53FBD9065B8B082 7585481276038A327CEF5A 150CAC67389&amp;p_insta nce=970034890998301&am p;p_flow_id=500&amp;p_fl ow_step_id=210">
  26. 26. @sthilaire wphilltech.com Report - Showing Contents
  27. 27. @sthilaire wphilltech.com Report – BLOB Field • When writing SQL, the report column is NOT the BLOB content Field – as much as a reference to the content
  28. 28. @sthilaire wphilltech.com Report – Numbers Required • The Report column is calculated as SIZE • Using the APEX format mask / generator, it must be a number.
  29. 29. @sthilaire wphilltech.com Report Content = SIZE • Note – You can store the size when the row is written for easy syntax
  30. 30. @sthilaire wphilltech.com Notes From the Field • The Mime Type and File Name is important for usability
  31. 31. @sthilaire wphilltech.com Notes From the Field • The report column containing the primary key must be named the same as the primary key field in the BLOB table – even if the BLOB table is not in the report • Fields are ignored based on format selections (inline vs. download)
  32. 32. @sthilaire wphilltech.com Report - Include Download
  33. 33. @sthilaire wphilltech.com Link Creation Result <a href="apex_util.get_blob?s=8634949024800&a mp;a=500&amp;c=3473415610798872&amp;p= 200&amp;k1=3418001856547833&amp;k2=&a mp;ck=BD47E34C8E5A3058299ECD457A4574B4 &amp;rt=IR" alt="Download" title="Download 58KB">Download</a>
  34. 34. @sthilaire wphilltech.com Notes From the Field • Case Sensitive Names “Apex_application_files” != APEX_APPLICATION_FILES
  35. 35. @sthilaire wphilltech.com Report - Include Image
  36. 36. @sthilaire wphilltech.com Report - Include Image As a Column in a Select Statement: CASE WHEN MIME_TYPE LIKE 'image%' THEN '<img src="'||apex_util.get_blob_file_src ( 'P210_BLOB_CONTENT',ID)|| '" height="75" width="75" />' ELSE NULL END as shrunk
  37. 37. @sthilaire wphilltech.com Text
  38. 38. @sthilaire wphilltech.com Quiz (A) (B) (C) (D) (E) (F) What is the size limit of a VARCHAR2? 255 2000 4000 32767 8 Terabytes Whatever it is defined as….
  39. 39. @sthilaire wphilltech.com Maximum Width
  40. 40. @sthilaire wphilltech.com Rich Text Editor Character Limit! Or The most descriptive error messages ever…
  41. 41. @sthilaire wphilltech.com Demonstration – Text Region Error
  42. 42. @sthilaire wphilltech.com Plugin – Rich Text
  43. 43. @sthilaire wphilltech.com The Next Level of Complexity
  44. 44. @sthilaire wphilltech.com Once Upon a Time…. @apexins.sql @apexins.sql Tablespace_apex SYSAUX tablespace_files SYSAUX tablespace_temp TEMP images /i/
  45. 45. @sthilaire wphilltech.com Specify LOB Storage Location CREATE TABLE ContainsLOB_tab ( n NUMBER, c CLOB) lob (c) STORE AS BASICFILE segname (TABLESPACE lobtbs1 CHUNK 4096 PCTVERSION 5 NOCACHE LOGGING STORAGE (MAXEXTENTS 5) );
  46. 46. @sthilaire wphilltech.com Demonstration – Text Region Plugin
  47. 47. @sthilaire wphilltech.com Size of Tables SELECT l.table_name||'-lob', s.bytes FROM user_lobs l, user_segments s WHERE s.segment_name = l.segment_name AND s.segment_type = 'LOBSEGMENT'
  48. 48. @sthilaire wphilltech.com Size Matters ALTER TABLE MY_TABLE DEALLOCATE UNUSED; ALTER TABLE MY_TABLE enable ROW MOVEMENT; ALTER TABLE MY_TABLE SHRINK SPACE cascade; ALTER TABLE MY_TABLE disable ROW MOVEMENT; Find a DBA to Partner With
  49. 49. @sthilaire wphilltech.com
  50. 50. @sthilaire wphilltech.com Questions and Comments
  51. 51. @sthilaire wphilltech.com References Many thanks to all those that have come before me, and for those that take the time to help others grow and improve their skills by sharing their time an knowledge. • Enkitec Plugin – http://www.enkitec.com/products/plugins • Demonstration Application – http://wphilltech.com • APEX Docs – BLOB in APEX 17.10 http://docs.oracle.com/cd/E37097_01/doc/doc.42/e35125/advnc_blob.htm#HTMDB25906 – GET_BLOB_FILE_SRC http://docs.oracle.com/cd/E37097_01/doc/doc.42/e35127/apex_util.htm#AEAPI129 • DBMS_LOB – http://docs.oracle.com/cd/E11882_01/appdev.112/e25788/d_lob.htm • Oracle SecureFiles and Large Objects – http://docs.oracle.com/cd/E11882_01/appdev.112/e18294/adlob_tables.htm – http://docs.oracle.com/cd/E11882_01/appdev.112/e18294/adlob_lob_ops.htm • APEX Builder - BLOB Support in Forms and Reports – http://docs.oracle.com/cd/E37097_01/doc/doc.42/e35125/advnc_blob.htm • Icons – http://www.stdicon.com/
  52. 52. @sthilaire wphilltech.com Disclaimer • Marks, images, brands and referenced content are the property of their respective owners. Usage is for discussion purposes only. No ownership assumed or implied. • The comments and opinions expressed here are sole responsibility of the author and not of his employer or any other party. • No trees were harmed during the creation of this presentation. However, a great number of electrons were terribly inconvenienced.

×