如何在Oracle中将LONG转换为CLOB

js81xvg6  于 2023-04-11  发布在  Oracle
关注(0)|答案(1)|浏览(506)

如何在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";

我不想使用这段代码,因为我不能更改表元素,也没有任何权限。

jaxagkaj

jaxagkaj1#

一个选择是只改变表。
下面是一个例子:
具有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,

OK,现在alter table修改longclob

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>

相关问题