loading an excel spreadsheet into an oracle table (oracle warehouse builder (owb))

Upload: bhaskararaosimma

Post on 01-Jun-2018

229 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/9/2019 Loading an Excel Spreadsheet Into an Oracle Table (Oracle Warehouse Builder (OWB))

    1/13

    Oracle

    Blogs HomeProducts & ServicesDownloadsSupport

    PartnersCommunitiesAboutLogin

    Oracle Blog

    Oracle Warehouse Builder (OWB)

    Getting the most out of OWB and the Oracle Database

    OWB at ODTUG's Kalei... | Main| Using DBMS Scheduler...

    Loading an Excel Spreadsheet into an Oracle Table

    By Alex Wu on Mar 01, 2010

    Recently we came across a question from the field about how an Excel spreadsheet can be loaded into anOracle table with the help of OWB 11GR2. There are many ways that this can be achieved. With OWB11GR2, the introduction of Code Template adds a new way of how a spreadsheet can be loaded. In this

    article, well review some ofthe old ways and explore the new way using OWB11GR2.

    Lets consider an example where we have 2 spreadsheets, hr_employees.xls and hr_departments.xls andwe want to load only the employees in the Sales department into the Oracle table. Following is thespreadsheet ofhr_department. And the columns from A to D are defined as department_id,department_name, manager_id and location_id.

    And the hr_employees spreadsheet looks like below. And the columns from A to K are defined asemployee_id, first_name, last_name, email, phone_number, hire_date, job_id, salary, commission_pct,manager_id and department_id.

    http://blogs.oracle.com/warehousebuilder/resource/WindowsLiveWriter-LoadinganExcelSpreadsheetintoanOracleTab_833/clip_image002_2.jpghttp://blogs.oracle.com/warehousebuilder/resource/WindowsLiveWriter-LoadinganExcelSpreadsheetintoanOracleTab_833/clip_image002_2.jpghttp://blogs.oracle.com/warehousebuilder/resource/WindowsLiveWriter-LoadinganExcelSpreadsheetintoanOracleTab_833/clip_image002_2.jpghttp://blogs.oracle.com/warehousebuilder/resource/WindowsLiveWriter-LoadinganExcelSpreadsheetintoanOracleTab_833/clip_image002_2.jpghttp://blogs.oracle.com/warehousebuilder/resource/WindowsLiveWriter-LoadinganExcelSpreadsheetintoanOracleTab_833/clip_image002_2.jpghttp://blogs.oracle.com/warehousebuilder/resource/WindowsLiveWriter-LoadinganExcelSpreadsheetintoanOracleTab_833/clip_image002_2.jpghttp://blogs.oracle.com/warehousebuilder/resource/WindowsLiveWriter-LoadinganExcelSpreadsheetintoanOracleTab_833/clip_image002_2.jpghttp://blogs.oracle.com/warehousebuilder/resource/WindowsLiveWriter-LoadinganExcelSpreadsheetintoanOracleTab_833/clip_image002_2.jpghttps://blogs.oracle.com/warehousebuilder/entry/owb_at_odtugs_kaleidoscope_2010https://blogs.oracle.com/warehousebuilder/https://blogs.oracle.com/warehousebuilder/entry/using_dbms_scheduler_with_owb_mappingshttps://blogs.oracle.com/warehousebuilder/https://blogs.oracle.com/roller-ui/login-redirect.rolhttp://www.oracle.com/us/community/index.htmlhttps://blogs.oracle.com/warehousebuilder/https://blogs.oracle.com/warehousebuilder/https://blogs.oracle.com/warehousebuilder/entry/owb_at_odtugs_kaleidoscope_2010http://www.oracle.com/http://www.oracle.com/us/corporate/index.htmlhttps://blogs.oracle.com/http://www.oracle.com/us/partnerships/index.htmlhttp://www.oracle.com/us/products/index.htmlhttp://blogs.oracle.com/warehousebuilder/resource/WindowsLiveWriter-LoadinganExcelSpreadsheetintoanOracleTab_833/clip_image002_2.jpghttps://blogs.oracle.com/warehousebuilder/entry/using_dbms_scheduler_with_owb_mappingshttp://www.oracle.com/technetwork/indexes/downloads/index.htmlhttp://www.oracle.com/us/community/index.htmlhttp://www.oracle.com/us/support/index.htmlhttps://blogs.oracle.com/roller-ui/login-redirect.rol
  • 8/9/2019 Loading an Excel Spreadsheet Into an Oracle Table (Oracle Warehouse Builder (OWB))

    2/13

    To make the scenario more interesting, we only want the employees in the Sales department in our resulttable. Below is the structure of the result table sales_employees where target data will be stored:

    To load the sales employees into the target table, we have to join the data from 2 spreadsheets by usingthe reference key department_id. Besides, the column employee_name in the target tablesales_employees is designed to include the first name and the last name of an employee. Hence, atransformation operator is needed. For example, we can utilize the Oracle pre-defined function CONCATto concatenate the names.

    Lets think about how to implement this in OWB 11GR2 release.

    1. The first way: access Excel spreadsheets through the Oracle Database Gateway for ODBC and load

    data by using PL/SQL mapping.

    The Oracle Database Gateway for ODBC can be set up to access an Excel file, making each spreadsheetin the Excel file looks as if it were an Oracle table. And we can make use of this to create a PL/SQLmapping in OWB to load the Excel data into an Oracle table. First, we need to set up the ODBC gatewayfor the Excel file (See "Using Excel Spreadsheets as Source"). In OWB, create an ODBC modulecorresponding to the ODBC gateway and invoke the Import Metadata Wizard to import the structures ofthe 2 spreadsheets into OWB. Then construct a PL/SQL mapping as follows.

    http://download.oracle.com/docs/cd/B28359_01/owb.111/b31278/case_load_ms_data.htm#sthref308http://blogs.oracle.com/warehousebuilder/resource/WindowsLiveWriter-LoadinganExcelSpreadsheetintoanOracleTab_833/clip_image004_2.jpghttp://blogs.oracle.com/warehousebuilder/resource/WindowsLiveWriter-LoadinganExcelSpreadsheetintoanOracleTab_833/clip_image006_2.jpg
  • 8/9/2019 Loading an Excel Spreadsheet Into an Oracle Table (Oracle Warehouse Builder (OWB))

    3/13

    The Joiner condition is configured as below.

    When its executed, OWB will read the data in spreadsheets through Oracle Database Gateway forODBC, transform and load them into the target table.

    2. The second way: utilize flat files and load data from converted CSV files to staging tables bySQL*Loader mapping, then load the target using PL/SQL mapping.

    2.1 First of all, we need to convert the Excel from XLS format into CSV or text format so that OWB flatfile can access it. This can be done by third-party tools or the Save As feature in Excel. In my case, Iopen the spreadsheets with Microsoft Excel, and save them as hr_employees.csv and hr_departments.csvrespectively. I also perform a Linux shell command dos2unix to convert any Windows characters intoUnix format, for my OWB repository is built on a Linux platform.

    2.2 Create an OWB flat file module referencing to the directory where the CSV files are, and use the

    Import Metadata Wizard to import the CSV files.

    2.3 Create 2 SQL*Loader mappings to load data into the staging tables as follows.

    http://blogs.oracle.com/warehousebuilder/resource/WindowsLiveWriter-LoadinganExcelSpreadsheetintoanOracleTab_833/odbc_map.pnghttp://blogs.oracle.com/warehousebuilder/resource/WindowsLiveWriter-LoadinganExcelSpreadsheetintoanOracleTab_833/join.png
  • 8/9/2019 Loading an Excel Spreadsheet Into an Oracle Table (Oracle Warehouse Builder (OWB))

    4/13

    This mapping will load the data in hr_departments.csv into the staging table STAGING_HR_DEPT.

    Note that the loading type has been configured as TRUNCATE/INSERT so that no duplicate data will beloaded into the staging table after multi-running.

    This mapping is to load the data in hr_employees.csv into staging table STAGING_HR_EMP, and the

    loading type is also set up as TRUNCATE/INSERT.

    2.4 Create a PL/SQL mapping to transform and load data from staging tables into final target as follows.

    http://blogs.oracle.com/warehousebuilder/resource/WindowsLiveWriter-LoadinganExcelSpreadsheetintoanOracleTab_833/sqdr2.pnghttp://blogs.oracle.com/warehousebuilder/resource/WindowsLiveWriter-LoadinganExcelSpreadsheetintoanOracleTab_833/sqdr1.png
  • 8/9/2019 Loading an Excel Spreadsheet Into an Oracle Table (Oracle Warehouse Builder (OWB))

    5/13

    Thats it. After deploying and executing the 3 mappings, data will be loaded into target.

    3. The third way: utilize Oracle External tables, extract and load data from external tables to the target byPL/SQL mapping.

    External table helps to expose data in a flat file as if it were a relational table. Thus its more flexible toinvolve external table operator as a source than the flat file operator in a mapping. OWB generates theSQL and PL/SQL codes for the mapping with external table, and more operators can be utilized in suchkind of mapping. As a result, only one PL/SQL mapping is needed to do the entire job.

    For this example, we create 2 external tables that reference the 2 CSV files respectively, and then we join

    them together to extract and transform the sales employees into the target table. And the PL/SQLmapping looks like this.

    External table operators and PL/SQL mappings allow for more complex mappings without the use ofstaging tables.

    http://blogs.oracle.com/warehousebuilder/resource/WindowsLiveWriter-LoadinganExcelSpreadsheetintoanOracleTab_833/map1.pnghttp://blogs.oracle.com/warehousebuilder/resource/WindowsLiveWriter-LoadinganExcelSpreadsheetintoanOracleTab_833/sqdr3.png
  • 8/9/2019 Loading an Excel Spreadsheet Into an Oracle Table (Oracle Warehouse Builder (OWB))

    6/13

    4. The fourth and newest way: extract and load data from the CSV files to the target table by CodeTemplate Mapping.

    In 11GR2, Code Template mapping (CT mapping) is introduced for heterogeneous data extraction,transformation and loading by using code templates. This enhances OWB to extract and load data (eitherwith or without transformation) between different database platforms easily. Each CT mapping containsone or more execution units, and each unit is independent and associated with one code template. Itutilizes the technology defined in the code template to move data, process data movement unit by unit,

    and then loads it into the final target. Because of the independency of each unit, CT Mapping allowsusers to handle data from different sources using different technologies.

    For this example, we include the 2 file operators (for the two CSV files) and the target table in a CTmapping, and then handle the ETL in 3 execution units as follows.

    Before deployment, we have to assign the code template to each execution unit, and configure the sourceflat files and locations of the file operators HR_EMPLOYEES_CSV and HR_DEPARTMENTS_CSV.

    To assign code template to an execution unit, open the CT mapping and select the execution view tab,and then select the execution unit box. And OWB will populate the available code templates shown inthe drop-down list. For example, when above execution unit DEPT_EX_UNIT is selected, severalavailable templates are shown, such as LCT_FILETO_SQL, LCT_FILE_TO_ORACLE_SQLLDR andLCT_FILE_TO_ORACLE_EXTER_TABLE. Though we have several options, we still need to

    determine which one is appropriate based upon your data and the functionality of the template. Besides,since each execution unit is independent, even if the execution unit DEPT_EX_UNIT andEMP_EX_UNIT are doing similar jobs, we can assign different code template to each of them. Forinstance, the DEPT_EX_UNIT can have code template LCT_FILE_TO_ORACLE_SQLLDR whileEMP_EX_UNIT can use another LCT_FILETO_SQL, as shown below. This greatly augments theflexibility of CT mapping.

    http://blogs.oracle.com/warehousebuilder/resource/WindowsLiveWriter-LoadinganExcelSpreadsheetintoanOracleTab_833/ct.png
  • 8/9/2019 Loading an Excel Spreadsheet Into an Oracle Table (Oracle Warehouse Builder (OWB))

    7/13

    If the flat file referenced by file operator is imported through Import Metadata Wizard, the CT mappingknows the location and the file physical name during code generation. However, we can still re-configure

    http://blogs.oracle.com/warehousebuilder/resource/WindowsLiveWriter-LoadinganExcelSpreadsheetintoanOracleTab_833/g2.pnghttp://blogs.oracle.com/warehousebuilder/resource/WindowsLiveWriter-LoadinganExcelSpreadsheetintoanOracleTab_833/g1.png
  • 8/9/2019 Loading an Excel Spreadsheet Into an Oracle Table (Oracle Warehouse Builder (OWB))

    8/13

    them in the mapping configuration editor if we want to change them. This should be done right before thefirst time code generation.

    Thats it, its ready to deploy and execute the CT mapping now. See the execution result below. Theexecution unit EMP_EX_UNIT and SALES_EX_UNIT utilize JDBC to load the data while executionunit DEPT_EX_UNIT uses SQL*Loader technology.

    CT mapping allows flexible technology for data movement, and the performance on large data volumesdepends on the code template applied. Though CT mapping allows more operators than SQL*Loadermapping, there may be some restrictions with the operators, for example, some operators can only besupported in the Oracle target CT mapping, such as Set Operation. For details, please refer to "MappingOperators that are Only Supported Directly in Oracle Target CT Mappings".

    So far, Ive illustrated 4 ways to load Excel spreadsheets into Oracle tables, which one is best suited for

    http://blogs.oracle.com/warehousebuilder/resource/WindowsLiveWriter-LoadinganExcelSpreadsheetintoanOracleTab_833/e1.pnghttp://download.oracle.com/docs/cd/E11882_01/owb.112/e10935/sap_km_mappings.htm#WBETL07012http://blogs.oracle.com/warehousebuilder/resource/WindowsLiveWriter-LoadinganExcelSpreadsheetintoanOracleTab_833/ct_map_conf2.png
  • 8/9/2019 Loading an Excel Spreadsheet Into an Oracle Table (Oracle Warehouse Builder (OWB))

    9/13

    your needs?

    Ways to loadExcelspreadsheet

    The 1stway:load datathrough ODBCgateway

    The 2ndway: load data from CSVfiles by SQL*Loader

    The 3rdway:load data withexternal tables

    The 4thway:load data bycode template

    Precondition ODBC gatewayfor Excel is setup.

    A CSV/ text file converted fromExcel is required

    Mapping type PL/SQLmapping

    SQL*Loader mapping & PL/SQLMapping if doing more transform

    PL/SQLmapping

    CT mapping

    Are staging

    table and extramappingrequired?

    No. Yes when there are more than one

    source files, or mapping is complex.

    No. No.

    What mappingoperators aresupported?

    High. It canoffer the fullrange ofWarehouseBuilder datatransformationcapabilities.

    Low. Only one flat file source isallowed within each mapping, andonly a few operators are applicable.See document "CreatingSQL*Loader Mappings to ExtractData from Flat Files".

    High. It cansupport the fullrange ofWarehouseBuilder datatransformationcapabilities.

    Middle. Morethan one fileoperators can beinvolved withinone mapping.CT mappingssupport only asubset oftransformationsavailable inPL/SQLmappings. See"MappingOperators thatare OnlySupported

    Directly inOracle TargetCT Mappings".

    Category: Oracle

    Tags: none

    Permanent link to this entry

    http://download.oracle.com/docs/cd/E11882_01/owb.112/e10935/sap_km_mappings.htm#WBETL07002http://download.oracle.com/docs/cd/E11882_01/owb.112/e10935/sap_km_mappings.htm#BABBIFHBhttps://blogs.oracle.com/warehousebuilder/entry/loading_an_excel_spreadsheet_into_an_oracle_table
  • 8/9/2019 Loading an Excel Spreadsheet Into an Oracle Table (Oracle Warehouse Builder (OWB))

    10/13

    OWB at ODTUG's Kalei... | Main| Using DBMS Scheduler...Comments:

    How to load SQL data to Oracle by scheduling a job that runs every 15 mins, taking the data for the slotof 15 minutes

    Posted by gueston July 06, 2011 at 08:18 PM PDT #

    how to import excel file to oracle table

    Posted by sukhviron May 24, 2012 at 04:47 AM PDT #

    Hi ,

    I am having a data in excel sheet (ex:- emp table ).I want that date to be inserted or copy into Oracle emp or any other table . How can i get this?

    Regards,Rajesh

    Posted by gueston July 03, 2013 at 03:29 AM PDT #

    Hi Rajesh

    Did you read through this in the dochttp://docs.oracle.com/cd/E11882_01/owb.112/e10582/loading_ms_data.htm

    CheersDavid

    Posted by Davidon July 08, 2013 at 01:28 PM PDT #

    Post a Comment:

    Name: guest

    E-Mail:

    URL:

    Notify me by email of new comments

    Remember Information?

    Your Comment:HTML Syntax: NOT allowed

    Please answer this simple math question

    https://blogs.oracle.com/warehousebuilder/entry/owb_at_odtugs_kaleidoscope_2010http://docs.oracle.com/cd/E11882_01/owb.112/e10582/loading_ms_data.htmhttps://blogs.oracle.com/warehousebuilder/entry/using_dbms_scheduler_with_owb_mappingshttps://blogs.oracle.com/warehousebuilder/http://-/?-http://-/?-http://-/?-http://-/?-
  • 8/9/2019 Loading an Excel Spreadsheet Into an Oracle Table (Oracle Warehouse Builder (OWB))

    11/13

  • 8/9/2019 Loading an Excel Spreadsheet Into an Oracle Table (Oracle Warehouse Builder (OWB))

    12/13

    dimensionELTelterrorerrorsETLetlexpert

    filegroovyhandlingintegrationloadingmappingMetadatametadatamigrationodiODI

    ombowbOWBOWB_11.2

    parallelperformanceProcess_FlowsdkSQLsql

    sqlloaderwarehouseWarehouse_Builderxml

    Categories

    OracleApplication ConnectorsCommentsData AuditorData QualityETL

    SAPEventsHow to ...MetadataODIPressResourcesSDK

    https://blogs.oracle.com/warehousebuilder/tags/etlhttps://blogs.oracle.com/warehousebuilder/category/Oracle/ETLhttps://blogs.oracle.com/warehousebuilder/tags/errorhttps://blogs.oracle.com/warehousebuilder/tags/integrationhttps://blogs.oracle.com/warehousebuilder/tags/ODIhttps://blogs.oracle.com/warehousebuilder/tags/owbhttps://blogs.oracle.com/warehousebuilder/tags/metadatahttps://blogs.oracle.com/warehousebuilder/tags/experthttps://blogs.oracle.com/warehousebuilder/tags/Metadatahttps://blogs.oracle.com/warehousebuilder/tags/errorshttps://blogs.oracle.com/warehousebuilder/category/Oracle/Application+Connectorshttps://blogs.oracle.com/warehousebuilder/tags/sqlloaderhttps://blogs.oracle.com/warehousebuilder/tags/xmlhttps://blogs.oracle.com/warehousebuilder/tags/loadinghttps://blogs.oracle.com/warehousebuilder/category/Oracle/Data+Auditorhttps://blogs.oracle.com/warehousebuilder/tags/ETLhttps://blogs.oracle.com/warehousebuilder/category/Oracle/ETL/SAPhttps://blogs.oracle.com/warehousebuilder/category/Oracle/Metadatahttps://blogs.oracle.com/warehousebuilder/tags/ombhttps://blogs.oracle.com/warehousebuilder/tags/dimensionhttps://blogs.oracle.com/warehousebuilder/tags/parallelhttps://blogs.oracle.com/warehousebuilder/category/Oracle/Data+Qualityhttps://blogs.oracle.com/warehousebuilder/tags/sqlhttps://blogs.oracle.com/warehousebuilder/tags/Process_Flowhttps://blogs.oracle.com/warehousebuilder/tags/warehousehttps://blogs.oracle.com/warehousebuilder/tags/mappinghttps://blogs.oracle.com/warehousebuilder/tags/odihttps://blogs.oracle.com/warehousebuilder/tags/OWB_11.2https://blogs.oracle.com/warehousebuilder/tags/elthttps://blogs.oracle.com/warehousebuilder/category/Oracle/How+to+...https://blogs.oracle.com/warehousebuilder/tags/migrationhttps://blogs.oracle.com/warehousebuilder/tags/performancehttps://blogs.oracle.com/warehousebuilder/category/Oracle/SDKhttps://blogs.oracle.com/warehousebuilder/tags/Warehouse_Builderhttps://blogs.oracle.com/warehousebuilder/tags/groovyhttps://blogs.oracle.com/warehousebuilder/tags/sdkhttps://blogs.oracle.com/warehousebuilder/category/Oracle/Resourceshttps://blogs.oracle.com/warehousebuilder/category/Oracle/Commentshttps://blogs.oracle.com/warehousebuilder/tags/ELThttps://blogs.oracle.com/warehousebuilder/tags/SQLhttps://blogs.oracle.com/warehousebuilder/category/Oracle/Presshttps://blogs.oracle.com/warehousebuilder/tags/OWBhttps://blogs.oracle.com/warehousebuilder/category/Oracle/ODIhttps://blogs.oracle.com/warehousebuilder/category/Oracle/Eventshttps://blogs.oracle.com/warehousebuilder/category/Oraclehttps://blogs.oracle.com/warehousebuilder/tags/handlinghttps://blogs.oracle.com/warehousebuilder/tags/file
  • 8/9/2019 Loading an Excel Spreadsheet Into an Oracle Table (Oracle Warehouse Builder (OWB))

    13/13

    SOA and Web ServicesSuccess StoriesUser-Contributed Contentmaster data management

    Archives

    January 2015

    Sun Mon Tue Wed Thu Fri Sat

    1 2 3

    4 5 6 7 8 9 10

    11 12 13 14 15 16 17

    18 19 20 21 22 23 24

    25 26 27 28 29 30 31

    Today

    Bookmarks

    OWB Blog Post Directory ArchiveData Warehouse InsiderRittman Mead BlogOracle Data Integration blogBig Data ForumsBI-Quotient (Uli)

    Menu

    Blogs HomeWeblogLogin

    Feeds

    RSS

    All/OracleComments

    Atom

    All/OracleComments

    The views expressed on this blog are those of the author and do not necessarily reflect the views ofOracle. Terms of Use| Your Privacy Rights | Cookie Preferences

    https://blogs.oracle.com/https://forums.oracle.com/forums/category.jspa?categoryID=512https://blogs.oracle.com/warehousebuilder/feed/entries/rsshttps://blogs.oracle.com/warehousebuilder/https://blogs.oracle.com/warehousebuilder/feed/comments/rsshttps://blogs.oracle.com/warehousebuilder/category/Oracle/Success+Storieshttp://blogs.oracle.com/datawarehousing/http://www.oracle.com/html/privacy.htmlhttps://blogs.oracle.com/warehousebuilder/category/Oracle/SOA+and+Web+Serviceshttp://www.rittmanmead.com/blog/http://blogs.oracle.com/dataintegration/https://blogs.oracle.com/warehousebuilder/feed/entries/atomhttps://blogs.oracle.com/warehousebuilder/category/Oracle/User-Contributed+Contenthttps://blogs.oracle.com/warehousebuilder/feed/comments/atomhttps://blogs.oracle.com/warehousebuilder/category/Oracle/master+data+managementhttp://www.business-intelligence-quotient.com/http://blogs.oracle.com/datawarehousing/https://blogs.oracle.com/warehousebuilder/feed/entries/rss?cat=%2FOraclehttp://www.business-intelligence-quotient.com/https://blogs.oracle.com/warehousebuilder/date/201409https://blogs.oracle.com/roller-ui/login-redirect.rolhttp://blogs.oracle.com/warehousebuilder/resource/archive_blog_07to11.htmlhttps://blogs.oracle.com/warehousebuilder/http://www.rittmanmead.com/blog/http://www.oracle.com/html/terms.htmlhttp://blogs.oracle.com/dataintegration/https://blogs.oracle.com/warehousebuilder/feed/entries/atom?cat=%2FOraclehttps://forums.oracle.com/forums/category.jspa?categoryID=512