1.12k likes | 1.3k Views
How Do I Load Data … Let Me Count The Ways. APEX Data Loading Options. Karen Cannell kcannell@thtechnology.com. http://www.thtechnology.com. How Do I Load Data? : Agenda. Oracle Data Loading Options DBAs - Developers - End Users APEX Data Loading Options File Upload
E N D
How Do I Load Data … Let Me Count The Ways APEX Data Loading Options Karen Cannell kcannell@thtechnology.com http://www.thtechnology.com
How Do I Load Data? : Agenda • Oracle Data Loading Options • DBAs - Developers - End Users • APEX Data Loading Options • File Upload • Data Load Wizard2 • XLS Upload – APEX Listener • WebSheets – Copy/Paste, Add Row
About Me … Karen Cannell ~ Consultant, TH Technology • SW Engineer 25+ years, Oracle since 1994. • Building APEX apps for government, medical, engineering industries. • Leveraging the Oracle 10g,11g (now 12c) suite of tools • Beginning Application Express, APress, 2011 • Agile Application Express, APress, 2011 • Editor, ODTUG Technical Journal Volunteer to author ODTUG Journal Articles! Using APEX since the HTMLDB beginning
About You … (Audience Background) • New to APEX? • APEX Experience? • Previous Tools? • APEX Training? • Version 2.0? 3.1 ? 3.2 ? 4.1?
How DO I Load Data into Oracle? Load Data Into Oracle 7,340,000 hits • SQL Loader • Oracle Database Utilities • Load Excel Data into Oracle
How DO I Load Data into Oracle? Load Data Into APEX 317,000 hits • Import Excel Data … • APEX Data Loader • Load Text File into APEX
How DO I Load Data into Oracle? Load XLS Data Into APEX 1,830,000 hits Yikes! • Import Excel File … • APEX Data Loader • Load Excel Data …
Load Data into Oracle - Options What Are the Options? • Commercial Solutions - Excel-DB, Quickload • Warehouse Builder, ETL Tools • Oracle Data Integrator http://www.oracle.com/technetwork/middleware/data-integrator/overview/index.html • Oracle Database Utilities • Oracle Data Pump • SQL Loader • External Tables
Load Data into Oracle, cont’d • ODBC Connections • IDEs w/built-In Data Loaders • Custom Code: • Java • PL/SQL Using UTL_FILE • Scripting from XLS Columns • Java and PL/SQL • Perl • Other
Load Data into APEX • Import Excel Data into Oracle … • APEX Data Loader • “Load Excel Data” The Apex Data Loader is a java based application that can bulk process the insert, update and delete on all object data into and build queries to extract data out of salesforce.com using the Apex Web Services (SOAP) API. 95% Say XLS but Really are CSV
Our Problem “Load Data into Oracle” • 40% Fixed-Format Text Files • 60% Excel Spreadsheets • Several XLS Formats • 200+ Files Monthly • Locations All Over the World • Some Networked, Some Not • Varying Volume of Data
Which to Choose? It Depends • Application • Source • Target ( Table?) • Amount of Data • How Often ? 1 or Many • Audience End Users • Resources $$ • Time $$
Which Make Sense for APEX ? • Oracle Database Utilities • PL/SQL IDE • No Additional Licenses • PL/SQL Code • No Complex Setup • Developer-Friendly • End User Friendly
Oracle Database Utilities • Oracle Data Pump • Oracle DB to Oracle DB • Faster than EXP and IMP • EXPDP 2x faster than EXP • IMPDP 15-45x faster than IMP • Jobs can be Restarted • Supports Network Import and Export • Load one instance form another • Remote export
Oracle Database Utilities, cont’d SQL Loader • External files into Tables • Variety of formats • Filtering • Multiple Table Load in One Load Session • Conventional • Direct Path • External Table Load
Oracle Database Utilities, cont’d External Tables • External files into Tables • Variety of Formats • Preprocessing Capability External Tables to Pull • RPT Files • CSV Files - That We Can Get
Oracle Database – Database Link • Don’t Forget the Database Link! SELECT … FROM table@db_link • Simple, Direct • Requires Communication • Ask!
Use your IDE • SQL Developer • PL/SQL Developer • Toad • Others … • Best for One-Time Load
SQL Developer – Data Load Option • Import Data … Wizard
SQL Developer – Import Data … Import File Formats • .XLS / XLSX • .CSV • .TSV (tab) • .DSV ( SQL Server)
SQL Developer – Import Data … Import Wiz Detects • File type • Delimiter • Skip Row
SQL Developer – Import Data … INSERT or Generate INSERT Script)
SQL Developer – Import Data … Select Columns to Import
SQL Developer – Import Data … Map Source to Table Columns
SQL Developer – Import Data … Finished! XLS and XLSX* File Load in Very Few Clicks! *XLSX in SQL Developer 3.1
SQL Developer – Import Data … What About XLSX? • SQL Dev 3.0 – No • SQL Developer 3.1 – Yes XLS/XLSX File Load in Very Few Clicks!
SQL Developer – Import Data … Pros Cons Table Must Be Defined Cannot Integrate into App Tedious to Repeat IDE Specific One Shot Data Load Not for End Users • One Shot Data Load • Delimiter (, TAB, others) • Flexible Columns • Flexible Mapping • XLS File • Can be Faster than APEX Data Load Wizard
APEX Data Load/Unload Utility • APEX From the Beginning • Easy Load of Spreadsheet or XML Data • New or Existing Table • Upload File Or Copy/Paste • Delimiter Option • Column by Column Selection
APEX Data Load/Unload Utility 1st Row Column Heading
APEX Data Load/Unload Utility Specify PK and Trigger Finish
APEX Data Load Utility Pros Cons Many Steps Single Table No XLS Upload (Must Copy/Paste or Save as CSV) One-Time Not for End Users • Simple: Point-Click-Done • Flexible Format • Spreadsheet Convenience • Creates Table • Copy/Paste Option
What About the End User? • APEX Standard File Browse + Custom Code • Data Load Wizard Wizard • APEX Manual Data Load Wizard End User-ized • APEX Web Sheet Data Grid • Copy/Paste, Data Entry • APEX Listener XLS Upload • File Browse + XLS2COLLECTION
APEX File Browse + Custom Code • Most Common (Still) • File Browse Item • Process (to Staging) • Process To Destination Table(s) • MANY MANY OPTIONS … All Require Custom Code
APEX File Browse + Custom Code • File Browse Item • WWV_FLOW_FILES – Original Way • BLOB column – New Option w APEX 4+
APEX File Browse + Custom Code WWV_FLOW_FILES – Traditional Way • File uploads to APEX Table WWV_FLOW_FILES • Move Records to a Custom Table (i.e. Staging Table) • Clean up! • Files accumulate in APEX_FILES Tablespace
APEX File Browse + Custom Code BLOB Column – New w/ APEX 4 • File Stored in BLOB Column of Table Specified in Automatic Row Processing (DML) Process • Column Specified in Item Source • Table Must Have • BLOB • Filename • MIME Type • CHARSET Saves an Archiving Step
APEX File Browse + Custom Code BLOB Column – New w/ APEX 4
APEX File Browse + Custom Code WWV_FLOW_FILES
APEX File Browse + Custom Code LOCAL_UPLOAD_FILES
APEX File Browse + Custom Code Parse / Load Process • Read Blob into local BLOB variable • Read Records from Blob • Load Records into Destination Objects
APEX File Browse + Custom Code Reusable Parse/ Load Process • File Browse Item • Load File to WWV_FLOW_FILE • Generic Parse File Package • Generic File Upload Utility • Generic Store to APEX Collection • Process Code per Use/Table/Format Custom Code, But Less of It
Generic Parse File Utility Package • Parse File to Collection • Load Collection to Specified Table • Columns Must Match, or Adjust Code • Reusable Code, Pages for Any Upload File/Table • Saves One Part of Custom Code • Custom Processing from Stage Table Required Custom Code, But Less of It
APEX File Browse + Custom Code Parse File Process • Read Blob into local BLOB variable BEGIN SELECT blob_content INTO l_blob FROM wwv_flow_files WHERE name=p_file_name; EXCEPTION WHEN NO_DATA_FOUND THEN raise_application_error(-20000, 'File not found, id='||p_file_name); END; Or BLOB column from your BLOB table
APEX File Browse + Custom Code Parse File Process • Read Records from Blob Variable TYPE varchar2_t IS TABLE OF VARCHAR2(32767) INDEX BY binary_integer; l_records VARCHAR2_T; … get_records(l_blob,l_records); … -- Initialize the APEX collection apex_collection.create_or_truncate_collection( p_collection_name);
PROCEDURE get_records(p_blob IN blob,p_records OUT varchar2_t) IS l_sepVARCHAR2(2) := chr(13)||chr(10); l_lastINTEGER; l_currentINTEGER; BEGIN IF (NVL(DBMS_LOB.INSTR(p_blob, utl_raw.cast_to_raw(l_sep),1,1),0)=0) THEN l_sep:= chr(10); END IF; l_last:= 1; LOOP l_current := dbms_lob.INSTR( p_blob, utl_raw.cast_to_raw(l_record_separator), l_last, 1 ); EXIT WHEN (nvl(l_current,0) = 0); p_records(p_records.count+1) := utl_raw.cast_to_varchar2( DBMS_LOB.SUBSTR(p_blob,l_current-l_last,l_last)); l_last := l_current+length(l_record_separator); END LOOP; END get_records;
LOOP l_current := dbms_lob.INSTR( p_blob, utl_raw.cast_to_raw(l_record_separator), l_last, 1 ); EXIT WHEN (nvl(l_current,0) = 0); p_records(p_records.count+1) := utl_raw.cast_to_varchar2( DBMS_LOB.SUBSTR(p_blob,l_current-l_last,l_last)); l_last := l_current+length(l_record_separator); END LOOP; Loop to read records from the BLOB, line by line (separator to separator)