Oracle PL/SQL Tutorial/Large Objects/TO LOB

Материал из SQL эксперт
Перейти к: навигация, поиск

Call to_lob to convert long to clob

SQL>
SQL> create table long_table
  2  ( id         int primary key,
  3    data       long
  4  )
  5  /
Table created.
SQL> create table clob_table as select id, to_lob(data) data from long_table;
Table created.
SQL>
SQL> insert into clob_table select id, to_lob(data) from long_table;
0 rows created.
SQL>
SQL> begin
  2      insert into clob_table select id, to_lob(data) from long_table;
  3  end;
  4  /
PL/SQL procedure successfully completed.
SQL>
SQL> drop table clob_table;
Table dropped.
SQL>
SQL> drop table long_table;
Table dropped.


TO_LOB demo

SQL>
SQL> CREATE TABLE myClobTable (id NUMBER,clob_data CLOB);
Table created.
SQL>
SQL> CREATE TABLE myLongTable (id NUMBER,long_data LONG);
Table created.
SQL>
SQL> INSERT INTO myLongTable VALUES (100,RPAD("A",200000,"A"));
1 row created.
SQL>
SQL>
SQL> INSERT INTO myClobTable
  2    SELECT id,TO_LOB(long_data)
  3    FROM myLongTable;
1 row created.
SQL>
SQL>
SQL> drop table myLongTable;
Table dropped.
SQL>
SQL>
SQL> drop table myClobTable;
Table dropped.
SQL>
SQL>
SQL>