You are on page 1of 52

@sthilaire wphilltech.

com

LOBS, BLOBS, CLOBS


Dealing with Attachments in APEX

Tim St. Hilaire


Feb 2014
@sthilaire wphilltech.com

The Plan

• Intro
• The Goal
• APEX BLOB Wizard
• Making It Your Own
• Base Technology
• Advanced Database Concepts
• Questions
@sthilaire wphilltech.com

Introduction
Tim St. Hilaire
• System Integrator
• Problems Solver
• Pragmatist
• Technology Enthusiast
• APEX Fan
• Enkitec Product Developer
@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
@sthilaire wphilltech.com

Demonstration – 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 – National Character Set LOB – stores Unicode
data
– BFILE – external LOB
– Secure File LOB – file data enabling advanced features
such as compression and encryption
@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

Demonstration - APEX Submit Button


@sthilaire wphilltech.com

Where did the file go?


WWV_FLOW_FILES
APEX_APPLICATION_FILES
@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
@sthilaire wphilltech.com

Evaluate WWV_FLOW_FILES
Pros Cons
• No Table Creations Required • Need Remote Key Storage
• Consistent Implementation • Application Files combined
• Storage in a known location • Storage for all Workspaces
is shared
• Some Files are publicly
available
@sthilaire wphilltech.com

Custom Table
@sthilaire wphilltech.com

My Table
• To configure your own table
• Minimum Requirements
• Adjust to Features and Business Requirements

ID NUMBER (your choice)


ACTUAL_FILE BLOB
MIME_TYPE VARCHAR2
FILE_NAME VARCHAR2
@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);
@sthilaire wphilltech.com

Referencing
@sthilaire wphilltech.com

Form - File Browse Settings


@sthilaire wphilltech.com

Form - Display Images


@sthilaire wphilltech.com

Form - Display Images


@sthilaire wphilltech.com

Form - Display Images


@sthilaire wphilltech.com

Form - Display Images


@sthilaire wphilltech.com

Form - Display Images


@sthilaire wphilltech.com

Form - Difference
<img id="P210_IMAGE" <img
src="apex_util.get_blob_file id="P210_IMAGE_SELECT"
?a=500&amp;s=9700348909 src="wwv_flow.show?p_req
98301&amp;p=210&amp;d= uest=NATIVE%3DC825C6CF6
27553826455759041&amp;i 97537EC53FBD9065B8B082
=27566106354076381&amp 7585481276038A327CEF5A
;p_pk1=3212306414813867 150CAC67389&amp;p_insta
83828770868593367722825 nce=970034890998301&am
&amp;p_pk2=&amp;p_ck=D p;p_flow_id=500&amp;p_fl
164075B30411E1CF29B6B9 ow_step_id=210">
ED9A57684" alt="Hunger"
title="Hunger">
@sthilaire wphilltech.com

Report - Showing Contents


@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
@sthilaire wphilltech.com

Report – Numbers Required


• The Report column is calculated as SIZE
• Using the APEX format mask / generator, it
must be a number.
@sthilaire wphilltech.com

Report Content = SIZE


• Note – You can store the size when the row is
written for easy syntax
@sthilaire wphilltech.com

Notes From the Field


• The Mime Type and File Name is important for
usability
@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)
@sthilaire wphilltech.com

Report - Include Download


@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>
@sthilaire wphilltech.com

Notes From the Field

• Case Sensitive Names


“Apex_application_files”
!=
APEX_APPLICATION_FILES
@sthilaire wphilltech.com

Report - Include Image


@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
What is the size limit of a VARCHAR2?
(A) 255
(B) 2000
(C) 4000
(D) 32767
(E) 8 Terabytes
(F) Whatever it is defined as….
@sthilaire wphilltech.com

Maximum Width
@sthilaire wphilltech.com

Rich Text Editor


Character Limit!
Or
The most descriptive error messages ever…
@sthilaire wphilltech.com

Demonstration – Text Region Error


@sthilaire wphilltech.com

Plugin – Rich Text


@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 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)
);
@sthilaire wphilltech.com

Demonstration – Text Region Plugin


@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 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


@sthilaire wphilltech.com
@sthilaire wphilltech.com

Questions and Comments


@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/
@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.

You might also like