Solved

Need help on sql

Posted on 2014-10-31
3
314 Views
Last Modified: 2014-11-03
Hi ,

I have an column called comments in COMMENTS table which is an CLOB column, I need to change the column data type from CLOB to VARCHAR2. Below is the code

DROP TABLE COMM_INTERIM;

CREATE TABLE COMM_INTERIM
   (      COMMENTARY_ID NUMBER ,
      SUBJECT VARCHAR2(400 CHAR) ,
      COMMENTS varchar2(4000 char),
      CREATED_BY NUMBER ,
      LAST_MODIFIED_DATE DATE,
      CREATED_DATE DATE ,
      LAST_MODIFIED_BY NUMBER ,
      VISIBILITY_TYPE NUMBER ,
      DEAL_GROUP_ID NUMBER ,
      LOCK_VERSION NUMBER ,
      VISIBILITY_RESOURCE_ID NUMBER ,
      DEAL_ID NUMBER,
      TRANCHE_ID NUMBER,
      ORGANIZATION1_ID NUMBER,
      ORGANIZATION1_MEMBER_ID NUMBER,
      ORGANIZATION2_ID NUMBER,
      ORGANIZATION2_MEMBER_ID NUMBER,
      ORGANIZATION3_ID NUMBER,
      ORGANIZATION3_MEMBER_ID NUMBER,
      EXTERNAL_ID VARCHAR2(100 CHAR),
      LEVEL_OF_ACCESS_ID NUMBER
   );


 Declare
col_mapping varchar2 (2000);
BEGIN
--  map all the columns in the interim table to the original table
col_mapping :=

                'COMMENTARY_ID COMMENTARY_ID , ' ||
    'SUBJECT SUBJECT , ' ||
    'DBMS_LOB.SUBSTR(COMMENTS,1,4000) COMMENTS , '||
    'CREATED_BY CREATED_BY, LAST_MODIFIED_DATE LAST_MODIFIED_DATE,'
    ||'CREATED_DATE CREATED_DATE , LAST_MODIFIED_BY LAST_MODIFIED_BY ,VISIBILITY_TYPE VISIBILITY_TYPE ,'    
    ||'DEAL_GROUP_ID DEAL_GROUP_ID,LOCK_VERSION LOCK_VERSION,VISIBILITY_RESOURCE_ID VISIBILITY_RESOURCE_ID,'||
    'DEAL_ID DEAL_ID,TRANCHE_ID TRANCHE_ID,ORGANIZATION1_ID ORGANIZATION1_ID,ORGANIZATION1_MEMBER_ID ORGANIZATION1_MEMBER_ID,'
    ||'ORGANIZATION2_ID ORGANIZATION2_ID,ORGANIZATION2_MEMBER_ID ORGANIZATION2_MEMBER_ID,ORGANIZATION3_ID ORGANIZATION3_ID,'
    ||'ORGANIZATION3_MEMBER_ID ORGANIZATION3_MEMBER_ID,EXTERNAL_ID EXTERNAL_ID,LEVEL_OF_ACCESS_ID LEVEL_OF_ACCESS_ID';
   
               
dbms_redefinition.start_redef_table('SCOTT', 'COMMENTS', 'COMM_INTERIM', col_mapping);
END;
/


declare
error_count pls_integer := 0;
BEGIN
  dbms_redefinition.copy_table_dependents('SCOTT', 'COMMENTS', 'COMM_INTERIM',
                                          1, true,true,true,false,
                                          error_count);

  dbms_output.put_line('errors := ' || to_char(error_count));
END;
/


exec  dbms_redefinition.finish_redef_table('SCOTT', 'COMMENTS', 'COMM_INTERIM');
/

After running the above script file geting the below error, any help is really appreciated.

Table created.


PL/SQL procedure successfully completed.


PL/SQL procedure successfully completed.


PL/SQL procedure successfully completed.

declare
*
ERROR at line 1:
ORA-23540: Redefinition not defined or initiated
ORA-06512: at "SYS.DBMS_SYS_ERROR", line 79
ORA-06512: at "SYS.DBMS_REDEFINITION", line 1809
ORA-06512: at line 4
0
Comment
Question by:sam_2012
3 Comments
 
LVL 76

Accepted Solution

by:
slightwv (䄆 Netminder) earned 250 total points
Comment Utility
It is here:
exec  dbms_redefinition.finish_redef_table('SCOTT', 'COMMENTS', 'COMM_INTERIM');
 /

Remove the '/' on the next line.

You only need a trailing '/' on pl/sql blocks.

The EXEC isn't a pl/sql block.

So the '/' is executing the last command in the buffer which was the exec.  Since the finish had already happened, there is nothing to finish the second time.
0
 
LVL 34

Assisted Solution

by:johnsone
johnsone earned 250 total points
Comment Utility
Just as an FYI, EXEC is really to be thought of as a macro.  If you issue:

exec  dbms_redefinition.finish_redef_table('SCOTT', 'COMMENTS', 'COMM_INTERIM');

What actually is run is:

begin dbms_redefinition.finish_redef_table('SCOTT', 'COMMENTS', 'COMM_INTERIM'); end;
/
0
 

Author Closing Comment

by:sam_2012
Comment Utility
awesome
0

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Join & Write a Comment

Suggested Solutions

Why doesn't the Oracle optimizer use my index? Querying too much data Most Oracle developers know that an index is useful when you can use it to restrict your result set to a small number of the total rows in a table. So, the obvious side…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Via a live example, show how to restore a database from backup after a simulated disk failure using RMAN.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now