please i want to read excel (.xlsx) from PLSQL ? is that possible or not ?
Question
Share
Sign Up to our social questions and Answers to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers to ask questions, answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
first thing data must be saved as extension .CSV not .xls
second we need to create directory and give (EXECUTE, READ, WRITE) privilege to appropriate user which will use this directory later into procedure we will create
create directory syntax
Note : “C:temp” this statement to create directory on windows server it will be little deference from Linux server.
third thing you need to create stage table which we will insert data into it by mapping excel column to be the same with columns name :
and now it’s time to read the data inside csv file and inserted to stage table by this procedure
create or replace procedure imp_proc_test is file_handle utl_file.file_type := UTL_FILE.FOPEN('TEMP_DIR','imptestdata.csv','R',5000); var1 test.TYPE_ID%type; v_string varchar2 (1000); begin loop begin UTL_FILE.get_line(file_handle,v_string); var1 := substr(v_string,1,instr(v_string,',',1,1)-1); insert into test (TYPE_ID) values (var1); exception when no_data_found then UTL_FILE.fclose (file_handle); exit; WHEN OTHERS THEN DBMS_OUTPUT.PUT_LINE(sqlcode||sqlerrm); end; end loop; commit; end;so now after created this procedure just call it by :
at the final there is too many ways to achieve this requirement but we pick easiest one for you so please if you have any addition just share with others here.