主要是用来存储大量数据的数据库字段,最大可以存储4G字节的非结构化数据。主要介绍字符类型和二进制文件类型LOB数据的存储,单独
三,大对象数据的读取和操作:DBMS_LOB包
DBMS_LOB包:包含处理大对象的过程和函数
/*
insert into tlob values(1,'Gene','CLOB大对象列',empty_blob(),bfilename('MYDIR','IMG_0210.JPG'));
insert into tlob values(2,'Jack','CLOB大对象列',empty_blob(),bfilename('MYDIR','IMG_0210.JPG'));
insert into tlob values(3,'Mary','大对象列CLOB',empty_blob(),bfilename('MYDIR','IMG_0210.JPG'));
*/
1,读取大对象数据的过程和函数
①:DBMS_LOB.Read():从LOB数据中读取指定长度数据到缓冲区的过程。
DBMS_LOB.Read(LOB数据,指定长度,起始位置,存储返回LOB类型值变量);
例子:
Declare
varC clob;
vRStr varchar2(1000);
ln number(4);
Strt number(4);
Begin
select resume into varC from tlob where no = 1;
ln := DBMS_LOB.GetLength(varC);
Strt := 1;
DBMS_LOB.Read(varC, ln, Strt, vRStr);
DBMS_output.put_line('Return: '||vRStr);
End;
②:DBMS_LOB.SubStr():从LOB数据中提取子字符串的函数。
DBMS_LOB.SubStr(LOB数据,指定提取长度,提取起始位置):
例子:
Declare
varC clob;
vRStr varchar2(1000);
ln number(4);
Strt number(4);
Begin
select resume into varC from tlob where no = 1;
ln := 4;
Strt := 1;
vRStr := DBMS_LOB.SubStr(varC, ln, Strt);
DBMS_output.put_line('结果为: '||vRStr);
End;
③:DBMS_LOB.InStr():从LOB数据中查找子字符串位置的函数。
DBMS_LOB.InStr(LOB数据, 子字符串);
例子:
Declare
varC clob;
vSubStr varchar2(1000);
vRStr varchar2(1000);
ln number(4);
Begin
select resume into varC from tlob where no = 1;
vSubStr := '大对象';
ln := DBMS_LOB.InStr(varC,vSubStr);
DBMS_output.put_line('位置为: '||ln);
vRStr := DBMS_LOB.SubStr(varC, Length(vSubStr), ln);
DBMS_output.put_line('位置为'||ln||'长度为'||Length(vSubStr)||'的子字符串为:'||vRStr);
End;
④:DBMS_LOB.GetLength():返回指定LOB数据的长度的函数。
DBMS_LOB.GetLength(LOB数据);
⑤:DBMS_LOB.Compare():比较二个大对象是否相等。返回数值0为相等,-1为不相等。
DBMS_LOB.Compare(LOB数据,LOB数据);
例子:
Declare
varC1 clob;
varC2 clob;
varC3 clob;
ln number(4);
Begin
select resume into varC1 from tlob where no = 1;
select resume into varC2 from tlob where no = 2;
select resume into varC3 from tlob where no = 3;
ln := DBMS_LOB.Compare(varC1,varC1);
DBMS_output.put_line('比较的结果为: '||ln);
ln := DBMS_LOB.Compare(varC2,varC3);
DBMS_output.put_line('比较的结果为: '||ln);
End;
2,操作大对象数据的过程
操作会改变数据库中原有数据,需要加上Updata锁锁上指定数据列,修改完后提交事务。
①:DBMS_LOB.Write():将指定数量的数据写入LOB的过程。
DBMS_LOB.Write(被写入LOB, 写入长度(指写入LOB数据),写入起始位置(指被写入LOB),写入LOB数据);
例子:
Declare
varC clob;
vWStr varchar2(1000);
vStrt number(4);
ln number(4);
Begin
vWStr := 'CLOB';
ln := Length(vWStr);
vStrt := 5;
select resume into varC from tlob where no = 1 FOR UPDATE;
DBMS_LOB.Write(varC, ln, vStrt, vWStr);
DBMS_output.put_line('改写结果为: '||varC);
Commit;
End;
②:DBMS_LOB.Append():将指定的LOB数据追加到指定的LOB数据后的过程。
DBMS_LOB.Append(LOB数据,LOB数据);
例子:
Declare
varC clob;
vAStr varchar2(1000);
Begin
vAStr := ',这是大对象列';
select resume into varC from tlob where no = 1 FOR UPDATE;
DBMS_LOB.Append(varC, vAStr);
commit;
DBMS_output.put_line('追加结果为: '||varC);
End;
③:DBMS_LOB.Erase():删除LOB数据中指定位置的部分数据的过程;
DBMS_LOB.Erase(LOB数据,指定删除长度, 开始删除位置);
例子:
Declare
varC clob;
ln number(4);
strt number(4);
Begin
ln := 1;
strt := 5;
select resume into varC from tlob where no = 1 FOR UPDATE;
DBMS_LOB.Erase(varC, ln, strt);
commit;
DBMS_output.put_line('擦除结果为: '||varC);
End;
④:DBMS_LOB.Trim():截断LOB数据中从第一位置开始指定长度的部分数据的过程;
DBMS_LOB.Trim(LOB数据,,截断长度);
例子:
Declare
varC clob;
ln number(4);
Begin
ln := 4;
select resume into varC from tlob where no = 1 FOR UPDATE;
DBMS_LOB.Trim(varC, ln);
COMMIT;
DBMS_output.put_line('截断结果为: '||varC);
End;
⑤:DBMS_LOB.Copy():从指定位置开始将源LOB复制到目标LOB;
DBMS_LOB.Copy(源LOB,目标LOB,复制源LOB长度,复制到目标LOB开始位置,复制源LOB开始位置)
例子:
Declare
vDEST_LOB clob;
vSRC_LOB clob;
AMOUNT number;
DEST_OFFSET number;
SRC_OFFSET number;
Begin
select resume into vDEST_LOB from tlob where no = 1 FOR UPDATE;
select resume into vSRC_LOB from tlob where no = 2 ;
AMOUNT := DBMS_LOB.GetLength(vSRC_LOB);
DEST_OFFSET := DBMS_LOB.GetLength(vDEST_LOB)+1;
SRC_OFFSET := 1;
DBMS_LOB.Copy(vDEST_LOB, vSRC_LOB, AMOUNT, DEST_OFFSET, SRC_OFFSET);
DBMS_output.put_line('拷贝结果为: '||vDEST_LOB);
End;

TograntpermissionstonewMySQLusers,followthesesteps:1)AccessMySQLasauserwithsufficientprivileges,2)CreateanewuserwiththeCREATEUSERcommand,3)UsetheGRANTcommandtospecifypermissionslikeSELECT,INSERT,UPDATE,orALLPRIVILEGESonspecificdatabasesortables,and4)

ToaddusersinMySQLeffectivelyandsecurely,followthesesteps:1)UsetheCREATEUSERstatementtoaddanewuser,specifyingthehostandastrongpassword.2)GrantnecessaryprivilegesusingtheGRANTstatement,adheringtotheprincipleofleastprivilege.3)Implementsecuritymeasuresl

ToaddanewuserwithcomplexpermissionsinMySQL,followthesesteps:1)CreatetheuserwithCREATEUSER'newuser'@'localhost'IDENTIFIEDBY'password';.2)Grantreadaccesstoalltablesin'mydatabase'withGRANTSELECTONmydatabase.TO'newuser'@'localhost';.3)Grantwriteaccessto'

The string data types in MySQL include CHAR, VARCHAR, BINARY, VARBINARY, BLOB, and TEXT. The collations determine the comparison and sorting of strings. 1.CHAR is suitable for fixed-length strings, VARCHAR is suitable for variable-length strings. 2.BINARY and VARBINARY are used for binary data, and BLOB and TEXT are used for large object data. 3. Sorting rules such as utf8mb4_unicode_ci ignores upper and lower case and is suitable for user names; utf8mb4_bin is case sensitive and is suitable for fields that require precise comparison.

The best MySQLVARCHAR column length selection should be based on data analysis, consider future growth, evaluate performance impacts, and character set requirements. 1) Analyze the data to determine typical lengths; 2) Reserve future expansion space; 3) Pay attention to the impact of large lengths on performance; 4) Consider the impact of character sets on storage. Through these steps, the efficiency and scalability of the database can be optimized.

MySQLBLOBshavelimits:TINYBLOB(255bytes),BLOB(65,535bytes),MEDIUMBLOB(16,777,215bytes),andLONGBLOB(4,294,967,295bytes).TouseBLOBseffectively:1)ConsiderperformanceimpactsandstorelargeBLOBsexternally;2)Managebackupsandreplicationcarefully;3)Usepathsinst

The best tools and technologies for automating the creation of users in MySQL include: 1. MySQLWorkbench, suitable for small to medium-sized environments, easy to use but high resource consumption; 2. Ansible, suitable for multi-server environments, simple but steep learning curve; 3. Custom Python scripts, flexible but need to ensure script security; 4. Puppet and Chef, suitable for large-scale environments, complex but scalable. Scale, learning curve and integration needs should be considered when choosing.

Yes,youcansearchinsideaBLOBinMySQLusingspecifictechniques.1)ConverttheBLOBtoaUTF-8stringwithCONVERTfunctionandsearchusingLIKE.2)ForcompressedBLOBs,useUNCOMPRESSbeforeconversion.3)Considerperformanceimpactsanddataencoding.4)Forcomplexdata,externalproc


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

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.
