Oracle 中LONG RAW BLOB CLOB类型介绍
Oracle 中LONG RAW BLOB CLOB类型介绍
说明:
RAW: 未加工类型,可存储二进制数据或字节符
LONG: 可变长的字符串数据,最长2G,LONG具有VARCHAR2列的特性,可以存储长文本一个表中最多一个LONG列【不建议使用】
LONG RAW: 可变长二进制数据,最长2G 【不建议使用】
CLOB: 字符大对象Clob 用来存储单字节的字符数据;大型文本,例如XML数据。
NCLOB: 用来存储多字节的字符数据
BLOB: 用于存储二进制大对象数据;例如数码照片;
BFILE: 存储在文件中的二进制数据,这个文件中的数据只能被只读访。但该文件不包含在数据库内。
bfile字段实际的文件存储在文件系统中,字段中存储的是文件定位指针.bfile对Oracle来说是只读的,也不参与事务性控制和数据恢复.
CLOB,,NCLOB,BLOB都是内部的LOB(Large Object)类型,最长4G,没有LONG只能有一列的限制
注意: LONG 和 LONG RAW在Oracle新版已不推荐使用(使用BLOB替代),只是为了向后兼容而保留着。
本文着重介绍:RAW/CLOB/BLOB
1、RAW类型
1.1 介绍
You use the RAW datatype to store binary data or byte strings. For example, a RAW
variable might store a sequence of graphics characters or a digitized picture. Raw data
is like VARCHAR2 data, except that PL/SQL does not interpret raw data. Likewise,
Oracle Net does no character set conversions when you transmit raw data from one
system to another.
The RAW datatype takes a required parameter that lets you specify a maximum size up
to 32767 bytes. The syntax follows:
RAW(maximum_size)
You cannot use a symbolic constant or variable to specify the maximum size; you must
use an integer literal in the range 1 .. 32767.
You cannot insert RAW values longer than 2000 bytes into a RAW column. You can insert
any RAW value into a LONG RAW database column because the maximum width of a
LONG RAW column is 2147483648 bytes or two gigabytes. However, you cannot retrieve
a value longer than 32767 bytes from a LONG RAW column into a RAW variable. Note
that the LONG RAW datatype is supported only for backward compatibility; see “LONG
and LONG RAW Datatypes” on page 3-5 for more information.
RAW英语的意思为:生的;未加工的;
你可以使用RAW类型存储二进制数据或字节符。例如,一个RAW变量可以存储一系列图形字符或一张数码照片。
RAW数据就像VARCHAR2数据,除了一点:PL/SQL不会对其进行解释。同样的,当你在传输RAW数据时,Oracle Net不会对其进行字符集转换。
RAW数据类型要求指定一个最大值到32767的参数;
声明格式如下: RAW(maximum_size)
你不能使用一个符号常量或变量来代替该参数而必须使用1..32767中的任一整数。
你不能往RAW列中插入超过2000字节的字符;
你可以往long raw列中插入任何raw数据,最大支持2G。然而,反过来则无法一次性取出超过32767字节的raw数据。
此处需要注意,long raw是早起版本的类型;现在已不建议使用;详细见以下内容:
1.2 相关工具
–包
utl_raw
–函数
utl_raw.cast_to_raw
utl_raw.cast_to_number
utl_raw.cast_to_varchar2
hextoraw
RAW保存的为16进制数。当使用HEXTORAW时,会把字符串中数据当作16进制数。
而使用UTL_RAW.CAST_TO_RAW时,直接把字符串中每个字符的ASCII码存放到RAW类型的字段中。
1.3 例子
drop table test_raw;
create table test_raw(msg raw(2000));
SCOTT@orcl> insert into test_raw values('
insert into test_raw values('
*
第 1 行出现错误:
ORA-01465: 无效的十六进制数字
--这个地方注意是十六进制
SCOTT@orcl> insert into test_raw values(utl_raw.cast_to_raw('
已创建 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)
------------------------------------------------------------------------------
可以使用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;
提交完成。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics

Full table scanning may be faster in MySQL than using indexes. Specific cases include: 1) the data volume is small; 2) when the query returns a large amount of data; 3) when the index column is not highly selective; 4) when the complex query. By analyzing query plans, optimizing indexes, avoiding over-index and regularly maintaining tables, you can make the best choices in practical applications.

Yes, MySQL can be installed on Windows 7, and although Microsoft has stopped supporting Windows 7, MySQL is still compatible with it. However, the following points should be noted during the installation process: Download the MySQL installer for Windows. Select the appropriate version of MySQL (community or enterprise). Select the appropriate installation directory and character set during the installation process. Set the root user password and keep it properly. Connect to the database for testing. Note the compatibility and security issues on Windows 7, and it is recommended to upgrade to a supported operating system.

InnoDB's full-text search capabilities are very powerful, which can significantly improve database query efficiency and ability to process large amounts of text data. 1) InnoDB implements full-text search through inverted indexing, supporting basic and advanced search queries. 2) Use MATCH and AGAINST keywords to search, support Boolean mode and phrase search. 3) Optimization methods include using word segmentation technology, periodic rebuilding of indexes and adjusting cache size to improve performance and accuracy.

The difference between clustered index and non-clustered index is: 1. Clustered index stores data rows in the index structure, which is suitable for querying by primary key and range. 2. The non-clustered index stores index key values and pointers to data rows, and is suitable for non-primary key column queries.

MySQL is an open source relational database management system. 1) Create database and tables: Use the CREATEDATABASE and CREATETABLE commands. 2) Basic operations: INSERT, UPDATE, DELETE and SELECT. 3) Advanced operations: JOIN, subquery and transaction processing. 4) Debugging skills: Check syntax, data type and permissions. 5) Optimization suggestions: Use indexes, avoid SELECT* and use transactions.

MySQL supports four index types: B-Tree, Hash, Full-text, and Spatial. 1.B-Tree index is suitable for equal value search, range query and sorting. 2. Hash index is suitable for equal value searches, but does not support range query and sorting. 3. Full-text index is used for full-text search and is suitable for processing large amounts of text data. 4. Spatial index is used for geospatial data query and is suitable for GIS applications.

In MySQL database, the relationship between the user and the database is defined by permissions and tables. The user has a username and password to access the database. Permissions are granted through the GRANT command, while the table is created by the CREATE TABLE command. To establish a relationship between a user and a database, you need to create a database, create a user, and then grant permissions.

MySQL and MariaDB can coexist, but need to be configured with caution. The key is to allocate different port numbers and data directories to each database, and adjust parameters such as memory allocation and cache size. Connection pooling, application configuration, and version differences also need to be considered and need to be carefully tested and planned to avoid pitfalls. Running two databases simultaneously can cause performance problems in situations where resources are limited.
