User`s guide
Exporting Data Using Bulk Insert
6-27
3
Enter data records. A sample record appears as follows.
A = {100000.00,'KGreen','06/22/2011','Challengers'};
4
Expand A to a 10,000-record data set.
A = A(ones(10000,1),:);
5
Write data to a file for bulk insert.
Tip When connecting to a database on a remote machine, you must write this file
to the remote machine. Oracle has problems trying to read files that are not on the
same machine as the instance of the database.
fid = fopen('c:\temp\tmp.txt','wt');
for i = 1:size(A,1)
fprintf(fid,'%10.2f \t %s \t %s \t %s \n',A{i,1},...
A{i,2},A{i,3},A{i,4});
end
fclose(fid);
6
Set the folder location.
e = exec(conn,...
'create or replace directory ext as ''C:\\Temp''');
close(e)
7
Delete the temporary table if it exists.
e = exec(conn,'drop table testinsert');
try,close(e),end
8
Create a temporary table and bulk insert it into the table BULKTEST.
e = exec(conn,['create table testinsert (salary number, '...
'player varchar2(25), signed varchar2(25), '...
'team varchar2(25)) organization external '...
'( type oracle_loader default directory ext access '...
'parameters ( records delimited by newline fields '...
'terminated by ''\t'') location (''tmp.txt'')) '...
'reject limit 10000']);
close(e)
e = exec(conn,'insert into BULKTEST select * from testinsert');
close(e)
9
Confirm the number of rows and columns in BULKTEST.
e = exec(conn, 'select * from BULKTEST');
results = fetch(e)