LOBS, BLOBS, CLOBS Dealing with Attachments in APEX

Transcription

LOBS, BLOBS, CLOBS Dealing with Attachments in APEX
@sthilaire wphilltech.com LOBS, BLOBS, CLOBS
Dealing with Attachments in APEX
Tim St. Hilaire
June 2013
@sthilaire wphilltech.com The Plan • 
• 
• 
• 
• 
• 
• 
Intro The Goal APEX BLOB Wizard Making It Your Own Base Technology Advanced Database Concepts QuesGons @sthilaire wphilltech.com IntroducGon
Tim St. Hilaire •  System Integrator •  Problems Solver •  PragmaGst •  Technology Enthusiast •  APEX Fan •  Enkitec Product Developer @sthilaire wphilltech.com The Goal •  Ability to accept file aNachment input from users in an applicaGon •  Use the content in applicaGons either as text, images, or downloadable to users •  Understand how the data is stored, retrieved, and managed inside the database @sthilaire wphilltech.com DemonstraGon – The Goal @sthilaire wphilltech.com The Academics @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 – NaGonal Character Set LOB – stores Unicode data •  BFILE – external LOB •  Secure File LOB – file data enabling advanced features such as compression and encrypGon @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'; @sthilaire wphilltech.com There are 10 types of people in the world… Those that understand binary, and those that don’t. -­‐-­‐ The Internet @sthilaire wphilltech.com APEX @sthilaire wphilltech.com DemonstraGon -­‐ APEX Submit BuNon @sthilaire wphilltech.com Where did the file go? WWV_FLOW_FILES APEX_APPLICATION_FILES @sthilaire wphilltech.com Table Context SensiGvity •  APEX_APPLICATION_FILES – limits to files available in the worksapce. •  Includes applicaGons that were uploaded by all applicaGons •  Includes files that have been uploaded via the builder •  Includes StaGc Shared Component Files for the ApplicaGon and the Workspace @sthilaire wphilltech.com Evaluate WWV_FLOW_FILES Pros •  No Table CreaGons Required •  Consistent ImplementaGon •  Storage in a known locaGon Cons •  Need Remote Key Storage •  ApplicaGon Files combined •  Storage for all Workspaces is shared @sthilaire wphilltech.com Custom Table @sthilaire wphilltech.com My Table •  To configure your own table •  Minimum Requirements •  Adjust to Features and Business Requirements BLOB_ID ACTUAL_FILE
FILE_NAME
MIMETYPE NUMBER (your choice) BLOB VARCHAR2 VARCHAR2 @sthilaire wphilltech.com Custom Table CREATE TABLE MY_APEX_FILES
(
BLOB_ID
NUMBER,
NAME
VARCHAR2(100 BYTE),
DESCRIPTION
VARCHAR2(2000 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
);
@sthilaire wphilltech.com Referencing @sthilaire wphilltech.com File Browse Sedngs @sthilaire wphilltech.com Display Images @sthilaire wphilltech.com Display Images @sthilaire wphilltech.com Display Images @sthilaire wphilltech.com Display Images @sthilaire wphilltech.com Showing Contents in a Report @sthilaire wphilltech.com Notes From the Field •  The Report column is NOT the BLOB content •  The Report column is calculated as SIZE •  The MIME_TYPE is important for usability @sthilaire wphilltech.com Report Content = SIZE @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 selecGons (inline vs. download) @sthilaire wphilltech.com Report -­‐ Include Download @sthilaire wphilltech.com Link CreaGon Result <a href="apex_uGl.get_blob?
s=8634949024800&amp;a=500&amp;c=347341
5610798872&amp;p=200&amp;k1=3418001856
547833&amp;k2=&amp;ck=BD47E34C8E5A3058
299ECD457A4574B4&amp;rt=IR" alt="Download" Gtle="Download 58KB">Download</a> @sthilaire wphilltech.com Notes From the Field •  Case SensiGve Names “Apex_applicaGon_files” != APEX_APPLICATION_FILES @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
@sthilaire wphilltech.com Text @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…. @sthilaire wphilltech.com Maximum Width @sthilaire wphilltech.com Rich Text Editor Character Limit! Or The most descripGve error messages ever… @sthilaire wphilltech.com DemonstraGon – Text Region Error @sthilaire wphilltech.com Plugin – Rich Text @sthilaire wphilltech.com DemonstraGon – Text Region Plugin @sthilaire wphilltech.com The Next Level of Complexity @sthilaire wphilltech.com Once Upon a Time…. @apexins.sql
@apexins.sql
Tablespace_apex
SYSAUX
tablespace_files
SYSAUX
tablespace_temp
TEMP
images
/i/
@sthilaire wphilltech.com Specify LOB Storage LocaGon 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)
);
@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'
@sthilaire wphilltech.com Size MaNers 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 @sthilaire wphilltech.com @sthilaire wphilltech.com QuesGons and Comments @sthilaire wphilltech.com References Many thanks to all those that have come before me, and for those that take the Gme to help others grow and improve their skills by sharing their Gme an knowledge. •  APEX Docs –  BLOB in APEX 17.10 hNp://docs.oracle.com/cd/E37097_01/doc/doc.42/e35125/advnc_blob.htm#HTMDB25906 –  GET_BLOB_FILE_SRC hNp://docs.oracle.com/cd/E37097_01/doc/doc.42/e35127/apex_uGl.htm#AEAPI129 •  DBMS_LOB –  hNp://docs.oracle.com/cd/E11882_01/appdev.112/e25788/d_lob.htm •  Oracle SecureFiles and Large Objects –  hNp://docs.oracle.com/cd/E11882_01/appdev.112/e18294/adlob_tables.htm –  hNp://docs.oracle.com/cd/E11882_01/appdev.112/e18294/adlob_lob_ops.htm •  APEX Builder -­‐ BLOB Support in Forms and Reports –  hNp://docs.oracle.com/cd/E37097_01/doc/doc.42/e35125/advnc_blob.htm •  Icons –  hNp://www.stdicon.com/ @sthilaire wphilltech.com Disclaimer •  Marks, images, brands and referenced content are the property of their respecGve 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 creaGon of this presentaGon. However, a great number of electrons were terribly inconvenienced.