This document discusses handling file attachments in Oracle Application Express (APEX) applications. It covers using BLOBs, CLOBs, and LOBs to store file attachments in the database; the APEX BLOB wizard; configuring a custom table; and displaying attachments in forms and reports. Advanced topics covered include LOB storage options, sizing database objects, and using a rich text editor plugin to handle text attachments. The goal is to understand how to accept, store, and display different file types uploaded by users in an APEX application.
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
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. @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';
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. @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
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
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. @sthilaire wphilltech.com
Report – Numbers Required
• The Report column is calculated as SIZE
• Using the APEX format mask / generator, it
must be a number.
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)
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
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. @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
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. @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.