VastbaseG100

基于openGauss内核开发的企业级关系型数据库。

Menu

TO_LOB

功能描述

TO_LOB函数用于将LONG或LONG RAW类型的值转换成LOB值,该函数只能应用于LONG或者LONG RAW列。

在使用此函数时需用创建一个LOB列来接受转换后的LONG值。转换LONG值请创建CLOB列,转换LONG RAW值请创建BLOB列。

注意事项

  • 该功能仅在数据库兼容模式为Oracle时支持(即数据库实例初始化时指定DBCOMPATIBILITY='A')。

  • 该功能仅在Vastbase G100 V2.2 Build 10(Patch No.9)及以后版本支持。

  • PL/SQL包中不能使用TO_LOB函数,可以使用TO_CLOB或TO_BLOB函数。

语法格式

TO_LOB(long_value)

参数说明

long_value

待转换的LONG或LONG RAW类型数据。

示例

示例1: LONG转换为CLOB。

1、创建数据类型为LONG的表,并插入数据。

create table test_long_1141359(c1 int, c2 long);
insert into test_long_1141359 values(1, 'test111');
insert into test_long_1141359 values(2, 'test222');

2、创建数据类型为clob的表。

create table test_clob_1141358(c1 int, c2 clob);

3、向test_clob_1141358表中插入数据。

insert into test_clob_1141358 select test_long_1141359.c1, TO_LOB(test_long_1141359.c2) c2 from test_long_1141359;

4、查询表结构和表中数据。

select * from test_clob_1141358;
\d+ test_clob_1141358;

返回结果如下所示,其中c2列数据类型已经被转换为clob类型:

 c1 |   c2
----+---------
  1 | test111
  2 | test222
(2 rows)

                   Table "public.test_clob_1141358"
 Column |  Type   | Modifiers | Storage  | Stats target | Description
--------+---------+-----------+----------+--------------+-------------
 c1     | integer |           | plain    |              |
 c2     | clob    |           | extended |              |
Has OIDs: no
Options: orientation=row, compression=no, fillfactor=80

示例2: LONG RAW转换为BLOB。

1、创建数据类型为LONG RAW的表,并插入数据。

create table test_long_1141174(c1 int, c2 long raw);
insert into test_long_1141174 values(1, UTL_RAW.CAST_TO_RAW('test111'));
insert into test_long_1141174 values(2, UTL_RAW.CAST_TO_RAW('test222'));

2、使用TO_LOB函数创建BLOB类型的表。

create table test_blob_1141174 as select test_long_1141174.c1, TO_LOB(test_long_1141174.c2) c2 from test_long_1141174;

3、查询表结构和表中数据。

select * from test_blob_1141174;
\d+ test_blob_1141174;

返回结果如下所示,其中c2列数据类型已经被转换为blob类型:

 c1 |       c2
----+----------------
  1 | 74657374313131
  2 | 74657374323232
(2 rows)

                   Table "public.test_blob_1141174"
 Column |  Type   | Modifiers | Storage  | Stats target | Description
--------+---------+-----------+----------+--------------+-------------
 c1     | integer |           | plain    |              |
 c2     | blob    |           | extended |              |
Has OIDs: no
Options: orientation=row, compression=no, fillfactor=80