Sunday, 26 June 2016

Loading the Data (.Csv) from File to Oracle Database

Follow Below steps:

Step 1: create a directory for placing the .csv file using SQL developer or TOAD or SQL*Plus or any              tool that connects with the database

create or replace directory OGL_REPORT_ACCESS as 'G:\ram_file_load_task';

step 2: place the .csv file in the above path mentioned in the step 1

       Note: Your .csv filename is "EmpData.csv"

step 3: create table for the inserting the data from the file we placed in step 2

create table ram_test(str varchar2(100));

step 4: here is the code :I am using UTL_File package in order to load from the file

set serveroutput on;
declare
fp utl_file.file_type;
str varchar2(500);
begin
fp := utl_file.fopen('OGL_REPORT_ACCESS','EmpData.csv','r');
--reading next lines and in put into ram_test table
loop
utl_file.get_line(fp,str);
insert into ram_test values(str);
end loop;
exception
when no_data_found then
commit;
end;
/
show errors;

step5: query the table whether data inserted or not.

select *from ram_test;

No comments:

Post a Comment