Question

I have to migrate a database to another. I have a dblink to make it easyier. Know I try to copy the colum comments and description from a table. The Problem is that the type is a CLOB. In the new database I use VARCHAR2. I used a workaround and created a global temporary table.

create global temporary table Comments
 (id number,description clob, comment clob) ON COMMIT PRESERVE ROWS; -

  insert into  Comments Select id,description,comment from database.test@DBLINK;

Now i have 52K rows in the table.

Now I want to create the new table test in the new database.

CREATE TABLE "TEST"
(
"ID"             NUMBER(9,0) NOT NULL ENABLE,
"NAME"             VARCHAR2(255) ,
"DESCRIPTION"             VARCHAR2(4000) ,
"COMMENT"             VARCHAR2(4000) ,
CONSTRAINT "TEST_PK" PRIMARY KEY ("ID")
);

And Now I try to insert the values:

insert into TEST(ID, NAME,DESCRIPTION, COMMENT)
 select Test_seq.nextval,Name,
  (select dbms_lob.substr(DESCRIPTION, 4000, 1) from  Comments b where b.id =a.id),
(select dbms_lob.substr(COMMENT, 4000, 1) from  Comments b where b.id =a.id),
from database.test@DBLINK a;

The problem is that it takes tooooooooooooo long to insert the values. I started it and it didn't finish after 30 minutes.

Is there a fast way to get convert clobs in varchar2 and insert them into a table in an other Oracle database?

Thanks for help!

Was it helpful?

Solution

Copy all columns on your temporary table then you should not query the main table:

CREATE GLOBAL TEMPORARY TABLE comments ON COMMIT PRESERVE ROWS 
    AS SELECT * FROM test@db;

SELECT INTO TEST(ID, NAME,DESCRIPTION, COMMENT)
SELECT ID, NAME, 
       dbms_lob.substr(description, 4000, 1), 
       dbms_lob.substr(description, 4000, 1)
  FROM comments;

Your query probably takes a lot of time because you are doing inline joins on a table that has no indexes (each row takes a FULL SCAN ! ).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top