How to change a dataype CLOB TO VARCHAR2(sql)

23,599

You may try this:

  1. Add a new column as varchar2

    alter table my_table add (new_column varchar2(1000));

  2. UPDATE CLOB name to varchar2 column;

    update my_table set new_column=dbms_lob.substr(old_column,1000,1);

After testing your data:

  1. DROP CLOB column

    alter table my_table drop column old_column

  2. Rename varchar2 column to CLOB column name

    alter table my_table rename column new_column to old_column

Share:
23,599

Related videos on Youtube

PHPnoob
Author by

PHPnoob

Updated on November 18, 2020

Comments

  • PHPnoob
    PHPnoob over 3 years

    Table: customers

    ID      NAME             DATATYPE
    NUMBER  VARCHAR2(100)    CLOB
    

    I want to change the DATA column from CLOB to `VARCHAR2(1000)

    I have try ALTER TABLE customers MODIFY DATA VARCHAR2 (1000) also

    ALTER TABLE customers MODIFY (DATA VARCHAR2 (1000))

    also

    alter table customers  modify
    (data VARCHAR2(4000))
    

    those normally works if the datatype is not a clob but I am getting a ORA-22859 because I am using oracle toad/apex.

  • PHPnoob
    PHPnoob over 10 years
    lol i was thinking the same but I can't do that. They should be away to change clob datatype
  • Rahul Tripathi
    Rahul Tripathi over 10 years
    They should be away to change clob datatype..What does that mean?
  • PHPnoob
    PHPnoob over 10 years
    it means changing clob to varachar2 or number same as you can change a varachar2(100) to varchar2(1000) or vaachar2 to number, etc
  • Rahul Tripathi
    Rahul Tripathi over 10 years
    @PHPnoob:- Updated my answer. Does that help?
  • PHPnoob
    PHPnoob over 10 years
    you want to me add a new colum while I am trying to change the existing colum datatype from clob to varchar2
  • Rahul Tripathi
    Rahul Tripathi over 10 years
    @PHPnoob:- I understand that but that would be the easiest one. Check this related thread: dba.stackexchange.com/questions/5948/…