0

Is there a way to create a new table(T1) from the CSV_data(BLOB) column of table(T2) in oracle SQL ?

I am able to do this with java, but it has performance issues as I have to first get the blob contents to java layer parse it and then create table and do batch insert. So, I want to know if we can do this directly at the database side itself ?

Many thanks in advance!

8
  • Possible, yes. But why do you want to copy data around? Commented May 27, 2021 at 12:49
  • You could do the same in the JVM running in the database (which would prevent to copy the data between the database and your client). You need only get the appropriate privileges from your DBA! Commented May 27, 2021 at 12:55
  • @jarlh I need to copy it to a table so that I can do additional inserts when next time same csv file is uploaded with next set of data. Also I will do operations like read/update. Commented May 27, 2021 at 12:56
  • 2
    With a CREATE PROCEDURE privilege you can CREATE JAVA stored procedure where you can set up a JDBC connection to the database (internal driver) and read the BLOB and insert to the new table without passing the data to client and back. Your user gets the privs once, you can execute it any times... Commented May 27, 2021 at 13:26
  • 2
    Why is the csv file being pulled into the database and saved as a blob in the first place? If you are going to parse it out and save the data in a conventional table, why not just use sqlldr to load that conventional table straight from the external csv file? Commented May 27, 2021 at 14:07

1 Answer 1

1

Also you can work with external tables.

It means that you can create a directory in Oracle, And use your CSV file such a table WITHOUT DML.

OracleDocsExternalTable

The basic command is:

CREATE OR REPLACE DIRECTORY EMP_DIR
AS 'E:\external';

SELECT * FROM ALL_DIRECTORIES
WHERE DIRECTORY_NAME='EMP_DIR';

CREATE TABLE EMP_LOAD_ext
     (EMPLOYEE_NUMBER      NUMBER,
      FNAME   VARCHAR2(100),
      LNAME   VARCHAR2(100)
      )
    ORGANIZATION EXTERNAL
      (TYPE ORACLE_LOADER
      DEFAULT DIRECTORY EMP_DIR
      ACCESS PARAMETERS
        (RECORDS DELIMITED BY NEWLINE
         FIELDS TERMINATED BY ','
        )
      LOCATION ('old_emp_data.csv')
     )
     reject limit unlimited;

I am not sure if you need something more to manage Clob an Blobs.

I found this other information.

ClobsAndBlobs

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks for your response! Unfortunately I need DML(update) for my usecase.
Maybe from this point you can copy it into table of your Instance... I think you can get some solution. Good Luck!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.