Migrating Oracle Database: Exporting an Oracle Database Table to a CSV File

Next, export the Oracle Database table to a CSV file. Run the following SQL script in SQL*Plus to select data from the OE.WLSLOG table and export to a wlslog.csv file.

set pagesize 0 linesize 500 trimspool on feedback off echo off

select ID || ‘,’ || TIME_STAMP || ‘,’ || CATEGORY || ‘,’ || TYPE || ‘,’ || SERVERNAME || ‘,’ || CODE || ‘,’ || MSG from OE.WLSLOG;

spool wlslog.csv

/

spool off

When the SQL script is run as shown in Figure 8-1, data is exported to the wlslog.csv file.

Remove the leading SQL> / and trailing SQL> spool off from the output exported to save the following as the wlslog.csv file. The leading and trailing lines are to be removed because the input to the mongoimport tool should be a CSV file.

catalog1,Apr-8-2014-7:06:l6-PM-PDT,Notice,WebLogicServer,AdminServer,BEA-000365,Server state changed to STANDBY

catalog2,Apr-8-2014-7:06:17-PM-PDT,Notice,WebLogicServer,AdminServer,BEA-000365,Server state changed to STARTING

catalog3,Apr-8-2014-7:06:18-PM-PDT,Notice,WebLogicServer,AdminServer,BEA-000365,Server state changed to ADMIN

catalog4,Apr-8-2014-7:06:19-PM-PDT,Notice,WebLogicServer,AdminServer,BEA-000365,Server state changed to RESUMING

catalog5,Apr-8-2014-7:06:20-PM-PDT,Notice,WebLogicServer,AdminServer,BEA-000361,Started WebLogic AdminServer

catalog6,Apr-8-2014-7:06:21-PM-PDT,Notice,WebLogicServer,AdminServer,BEA-000365,Server state changed to RUNNING

catalog7,Apr-8-2014-7:06:22-PM-PDT,Notice,WebLogicServer,AdminServer,BEA-000360,Server started in RUNNING mode

Source: Vohra Deepak (2015), Pro MongoDB™ Development, Apress; 1st ed. edition.

Leave a Reply

Your email address will not be published. Required fields are marked *