ORA-22858: 資料類型的變更無效 varchar2類型轉換為clob類型

來源:互聯網
上載者:User

Oracle中,如果一個列的類型為varchar2,那麼它不能直接轉換為clob類型。可以通過間接的方式來修改。下面為實驗:

SQL>create table test(id int,name varchar2(10));

Tablecreated

SQL>insert into test values(1,'a');

1row inserted

SQL>insert into test values(2,'b');

1row inserted

SQL>commit;

Commitcomplete

SQL>select * from test;

    ID  NAME

---------------------------------------

  1      a

  2      b

 SQL> desc test

NameType        Nullable Default Comments

---------------- -------- ------- --------

ID  INTEGER    Y                       

NAMEVARCHAR2(10) Y                       

 

SQL> alter table test modify(name clob);

 altertable test modify (name clob)

 ORA-22858: 資料類型的變更無效

 如果直接轉換,報錯!

 


我們可以通過間接的方式來操作:

建立一個clob類型的列,將原列的值插入建立的列,然後刪除原列,重新命名新列。

 

SQL> alter table test add name1clob;

 Table altered

 SQL> update test setname1=name;

 2rows updated

 SQL> select * from test;

 

                                    IDNAME      NAME1

----------------------------------------------------------------------------------

                                      1 a          a

                                      2 b          b

 

SQL> desc test

Name  Type        Nullable Default Comments

----------------- -------- ------- --------

ID    INTEGER    Y                       

NAME  VARCHAR2(10) Y                       

NAME1CLOB        Y                       

 

SQL> commit;

Commit complete

SQL> alter table test dropcolumn name;

Table altered

SQL> alter table test renamecolumn name1 to name;

Table altered

SQL> select * from test;

                                    ID NAME

---------------------------------------------------------------------

                                      1 a

                                      2 b

SQL> desc test

NameType    Nullable Default Comments

----------- -------- ------- --------

ID  INTEGER Y                       

NAMECLOB    Y     

GoldenGate不使用資料泵完成Oracle-Oracle的雙向複製

使用GoldenGate的資料泵進行Oracle-Oracle的單向複製

如何對 Oracle 資料泵(expdp/impdp) 進行 debug

Oracle 資料庫匯出資料泵(EXPDP)檔案存放的位置

Oracle 10g 資料泵分區表的匯出

相關文章

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.