如何在 Oracle 中使用函数将 LONG 数据类型更改为 CLOB?
ALTER TABLE "TABLE_NAME"
ADD "CLOB_NAME" CLOB;
UPDATE "TABLE_NAME"
SET "CLOB_NAME" = TO_CLOB("LONG_NAME");
ALTER TABLE "TABLE_NAME"
DROP CLOUMN "LONG_NAME";
ALTER TABLE "TABLE_NAME"
RENAME CLOUMN "CLOB_NAME" TO "LONG_NAME";
我不想使用该代码,因为我无法更改表格元素并且没有任何权限。
一个选择是只改变表。
举个例子:
带有
long
数据类型列的表:
SQL> create table test (col long);
Table created.
让我们填充它:
SQL> begin
2 for cur_r in (select text from all_views
3 where text_length < 30000
4 and text is not null
5 )
6 loop
7 insert into test (col) values (cur_r.text);
8 end loop;
9 end;
10 /
PL/SQL procedure successfully completed.
它包含多少行?
SQL> select count(*) from test;
COUNT(*)
----------
45
摘录:
SQL> select * from test where rownum = 1;
COL
--------------------------------------------------------------------------------
SELECT q_name QUEUE, qt.msgid MSG_ID, corrid CORR_ID, priority MSG_PRIORITY,
好的;现在,alter table 并将
long
修改为 clob
:
SQL> alter table test modify col clob;
Table altered.
结果:
SQL> select * from test where rownum = 1;
COL
--------------------------------------------------------------------------------
SELECT q_name QUEUE, qt.msgid MSG_ID, corrid CORR_ID, priority MSG_PRIORITY,
SQL>