当前位置:Gxlcms > 数据库问题 > Oracle 中LONG RAW BLOB CLOB类型介绍

Oracle 中LONG RAW BLOB CLOB类型介绍

时间:2021-07-01 10:21:17 帮助过:2人阅读

)); SCOTT@orcl> insert into test_raw values(<xml><name>Dylan</name><score>100</score></xml>‘); insert into test_raw values(<xml><name>Dylan</name><score>100</score></xml>‘) * 第 1 行出现错误: ORA-01465: 无效的十六进制数字 --这个地方注意是十六进制 SCOTT@orcl> insert into test_raw values(utl_raw.cast_to_raw(<xml><name>Dylan</name><score>100</score></xml>‘)); 已创建 1 行。 SCOTT@orcl> commit; --查看 select msg from test_raw; MSG ------------------------------------------------------------------------------ 3C786D6C3E3C6E616D653E44796C616E3C2F6E616D653E3C73636F72653E3130303C2F73636F72 653E3C2F786D6C3E 0ABC SCOTT@orcl> select utl_raw.cast_to_varchar2(msg) from test_raw; UTL_RAW.CAST_TO_VARCHAR2(MSG) ------------------------------------------------------------------------------ <xml><name>Dylan</name><score>100</score></xml>

2、LONG和LONG RAW类型

可以使用LONG类型存储变长字符串。Long类型就像VARCHAR2一样,除了LONG的最大容量为32760;

使用LONG RAW类型存储二进制数据或字节字符串。LONG RAW数据就像LONG数据,除了LONG RAW数据不会被PL/SQL解释。
LONG RAW的最大容量也为32760.

你可以往LONG列中插入任何LONG数据,最大长度为2G。然而,PL/SQL中的LONG类型变量只能支持到32760。
这条规则同样适用于LONG RAW类型。

表中的LONG列可以存储文本,字符数组,甚至短文档。可以针对该类型列做UPDATE, INSERT, 和SELECT 操作。
但是无法再表达式,SQL函数调用或特定的SQL条件语句例如WHERE, GROUP BY和CONNECT BY。

In SQL statements, PL/SQL binds LONG values as VARCHAR2, not as LONG. However,
if the length of the bound VARCHAR2 exceeds the maximum width of a VARCHAR2
column (4000 bytes), Oracle converts the bind type to LONG automatically, then issues
an error message because you cannot pass LONG values to a SQL function

SQL语句中, PL/SQL将LONG类型作为VARCHAR2类型绑定。然而,如果所绑定的VARCHAR2长度超出了4000,ORACLE会自动转换到LONG,
然后抛出一个错误因为你不能将LONG值传递给SQL函数。

--例如:
SCOTT@orcl> create table long_test(id number, msg long);

表已创建。

SCOTT@orcl> insert into long_test values(1,‘hello world‘);

已创建 1 行。

SCOTT@orcl> commit;

提交完成。

SCOTT@orcl> select * from long_test where msg=‘123‘;
select * from long_test where msg=‘123‘
                              *
第 1 行出现错误:
ORA-00997: 非法使用 LONG 数据类型


SCOTT@orcl> /

        ID MSG
---------- --------------------------------------------------------------------------------
         1 hello world

SCOTT@orcl> select id, trim(msg) from long_test where id = 1;
select id, trim(msg) from long_test where id = 1
                *
第 1 行出现错误:
ORA-00932: 数据类型不一致: 应为 NUMBER, 但却获得 LONG

3、CLOB
可以使用CLOB类型大块的字符数据。每一个CLOB变量存储一个定位器,指向一个大块字符数据。

CLOBs participate fully in transactions, are recoverable, and can be replicated. Changes
made by package DBMS_LOB can be committed or rolled back. CLOB locators can span
transactions (for reads only), but they cannot span sessions.

CLOB参与整体事务,可恢复,并且可以重复。
由DBMS_LOB包改变的数据可以提交和回滚。CLOB定位器可以跨事务,但不能跨会话。

4、BLOB
You use the BLOB datatype to store large binary objects in the database, in-line or
out-of-line. Every BLOB variable stores a locator, which points to a large binary object.
BLOBs participate fully in transactions, are recoverable, and can be replicated. Changes
made by package DBMS_LOB can be committed or rolled back. BLOB locators can span
transactions (for reads only), but they cannot span sessions.

用于存储大二进制对象,BLOB参与整体事务,可恢复,并且可以重复。
由DBMS_LOB包改变的数据可以提交和回滚。BLOB定位器可以跨事务,但不能跨会话。

drop table blob_test;

SCOTT@orcl>  create table blob_test(   id number primary key,   content blob not null);

表已创建。

SCOTT@orcl> insert into blob_test values(1,‘11111000011111‘);

已创建 1 行。

SCOTT@orcl> commit;

提交完成。

SCOTT@orcl> select * from blob_test;

SCOTT@orcl> set linesize 2000
SCOTT@orcl> /

        ID CONTENT
---------- -----------------------------------
         1 11111000011111


SCOTT@orcl> insert into blob_test values(1,‘11111000011111>‘);
insert into blob_test values(1,‘11111000011111>‘)
                                             *
第 1 行出现错误:
ORA-01465: 无效的十六进制数字


 SCOTT@orcl> update blob_test set content=to_blob(‘110010000110011‘) where id=1;

已更新 1 行。

SCOTT@orcl> rollback
  2  ;

回退已完成。

SCOTT@orcl> select * from blob_test;

        ID CONTENT
---------- ---------------------------------------------------------------------
         1 11111000011111

 delete from blob_test where id=1; 
 commit;

版权声明:本文为博主原创文章,未经博主允许不得转载。

Oracle 中LONG RAW BLOB CLOB类型介绍

标签:

人气教程排行