I am currently facing an issue(below is the error code) when trying to import data from a .csv file to OracleDB. Now, I have a stored procedure so that I could easily call it out. Now, every time I try to run or call the stored procedure it gives me an error(error code below)
So this is my stored procedure called load_csv_into_employee
;
CREATE OR REPLACE PROCEDURE load_csv_into_employee AS
v_count NUMBER;
BEGIN
-- Check if the external table already exists
SELECT COUNT(*)
INTO v_count
FROM user_tables
WHERE table_name = 'CSV_TABLE';
-- If the external table doesn't exist, create it
IF v_count = 0 THEN
EXECUTE IMMEDIATE '
CREATE TABLE csv_table (
EMPLOYEE_ID VARCHAR2(50),
FIRST_NAME VARCHAR2(100),
LAST_NAME VARCHAR2(100),
DEPARTMENT VARCHAR2(200)
)
ORGANIZATION EXTERNAL (
TYPE ORACLE_LOADER
DEFAULT DIRECTORY csv_dir
ACCESS PARAMETERS (
RECORDS DELIMITED BY NEWLINE
FIELDS TERMINATED BY '',''
MISSING FIELD VALUES ARE NULL
)
LOCATION (''\directorypathyour_file.csv'')
)';
END IF;
-- Insert data into EMPLOYEE
EXECUTE IMMEDIATE '
INSERT INTO EMPLOYEE
SELECT * FROM csv_table';
-- Drop the external table
EXECUTE IMMEDIATE 'DROP TABLE csv_table';
COMMIT;
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('Error: ' || SQLERRM);
END load_csv_into_employee;
/
However it gives me this error every time I execute it:
Error: ORA-29913: error in executing ODCIEXTTABLEOPEN callout
.
I tried(Most of the answers I searched they based on permission issue):
- I have tried researching here and found that there might be a permission issues. So I made sure that I have created the
csv_dir
using the syntax
CREATE DIRECTORY csv_dir AS '\dirpathyour_file.csv';
and also made sure that I have granted it with permission.GRANT READ, WRITE ON DIRECTORY csv_dir TO MyUserName;
. I used thesys as sysdba
user to grant permission for this one
Note: I am currently just trying to test and learn so I had to use the SYS user.