dbms_lob包学习笔记之三:instr和substr存储过程
2010-09-17 23:22
357 查看
转载于:/article/5900786.html
dbms_lob包学习笔记之三:instr和substr存储过程
http://wwwwwfco.itpub.net/post/5073/27882
instr和substr存储过程,分析内部大对象的内容
instr函数与substr函数
instr函数用于从指定的位置开始,从大型对象中查找第N个与模式匹配的字符串。
用于查找内部大对象中的字符串的instr函数语法如下:
dbms_lob.instr(
lob_loc in blob,
pattern in raw,
offset in integer := 1;
nth in integer := 1)
return integer;
dbms_lob.instr(
lob_loc in clob character set any_cs,
pattern in varchar2 character set lob_loc%charset,
offset in integer:=1,
nth in integer := 1)
return integer;
lob_loc为内部大对象的定位器
pattern是要匹配的模式
offset是要搜索匹配文件的开始位置
nth是要进行的第N次匹配
substr函数
substr函数用于从大对象中抽取指定数码的字节。当我们只需要大对象的一部分时,通常使用这个函数。
操作内部大对象的substr函数语法如下:
dbms_lob.substr(
lob_loc in blob,
amount in integer := 32767,
offset in integer := 1)
return raw;
dbms_lob.substr(
lob_loc in clob character set any_cs,
amount in integer := 32767,
offset in integer := 1)
return varchar2 character set lob_loc%charset;
其中各个参数的含义如下:
lob_loc是substr函数要操作的大型对象定位器
amount是要从大型对象中抽取的字节数
offset是指从大型对象的什么位置开始抽取数据。
如果从大型对象中抽取数据成功,则这个函数返回一个 raw 值。如果有一下情况,则返回null:
1 任何输入参数尾null
2 amount < 1
3 amount > 32767
4 offset < 1
5 offset > LOBMAXSIZE
示例如下:
declare
source_lob clob;
pattern varchar2(6) := 'Oracle';
start_location integer := 1;
nth_occurrence integer := 1;
position integer;
buffer varchar2(100);
begin
select clob_locator into source_lob from mylobs where lob_index = 4;
position := dbms_lob.instr(source_lob, pattern, start_location, nth_occurrence);
dbms_output.put_line('The first occurrence starts at position:' || position);
nth_occurrence := 2;
select clob_locator into source_lob from mylobs where lob_index = 4;
position := dbms_lob.instr(source_lob, pattern, start_location, nth_occurrence);
dbms_output.put_line('The first occurrence starts at position:' || position);
select clob_locator into source_lob from mylobs where lob_index = 5;
buffer := dbms_lob.substr(source_lob, 9, start_location);
dbms_output.put_line('The substring extracted is: ' || buffer);
end;
/
The first occurrence starts at position:8
The first occurrence starts at position:24
The substring extracted is: Oracle 9i
PL/SQL 过程已成功完成。
dbms_lob包学习笔记之三:instr和substr存储过程
http://wwwwwfco.itpub.net/post/5073/27882
instr和substr存储过程,分析内部大对象的内容
instr函数与substr函数
instr函数用于从指定的位置开始,从大型对象中查找第N个与模式匹配的字符串。
用于查找内部大对象中的字符串的instr函数语法如下:
dbms_lob.instr(
lob_loc in blob,
pattern in raw,
offset in integer := 1;
nth in integer := 1)
return integer;
dbms_lob.instr(
lob_loc in clob character set any_cs,
pattern in varchar2 character set lob_loc%charset,
offset in integer:=1,
nth in integer := 1)
return integer;
lob_loc为内部大对象的定位器
pattern是要匹配的模式
offset是要搜索匹配文件的开始位置
nth是要进行的第N次匹配
substr函数
substr函数用于从大对象中抽取指定数码的字节。当我们只需要大对象的一部分时,通常使用这个函数。
操作内部大对象的substr函数语法如下:
dbms_lob.substr(
lob_loc in blob,
amount in integer := 32767,
offset in integer := 1)
return raw;
dbms_lob.substr(
lob_loc in clob character set any_cs,
amount in integer := 32767,
offset in integer := 1)
return varchar2 character set lob_loc%charset;
其中各个参数的含义如下:
lob_loc是substr函数要操作的大型对象定位器
amount是要从大型对象中抽取的字节数
offset是指从大型对象的什么位置开始抽取数据。
如果从大型对象中抽取数据成功,则这个函数返回一个 raw 值。如果有一下情况,则返回null:
1 任何输入参数尾null
2 amount < 1
3 amount > 32767
4 offset < 1
5 offset > LOBMAXSIZE
示例如下:
declare
source_lob clob;
pattern varchar2(6) := 'Oracle';
start_location integer := 1;
nth_occurrence integer := 1;
position integer;
buffer varchar2(100);
begin
select clob_locator into source_lob from mylobs where lob_index = 4;
position := dbms_lob.instr(source_lob, pattern, start_location, nth_occurrence);
dbms_output.put_line('The first occurrence starts at position:' || position);
nth_occurrence := 2;
select clob_locator into source_lob from mylobs where lob_index = 4;
position := dbms_lob.instr(source_lob, pattern, start_location, nth_occurrence);
dbms_output.put_line('The first occurrence starts at position:' || position);
select clob_locator into source_lob from mylobs where lob_index = 5;
buffer := dbms_lob.substr(source_lob, 9, start_location);
dbms_output.put_line('The substring extracted is: ' || buffer);
end;
/
The first occurrence starts at position:8
The first occurrence starts at position:24
The substring extracted is: Oracle 9i
PL/SQL 过程已成功完成。
相关文章推荐
- dbms_lob包学习笔记之三:instr和substr存储过程
- dbms_lob包学习笔记之三:instr和substr存储过程
- dbms_lob包学习笔记之二:append和write存储过程
- DBMS_LOB的instr与substr
- sqlServer2000存储过程学习笔记
- Oracle 学习笔记 18 -- 存储函数和存储过程(PL/SQL子程序)
- 【数据库学习笔记】Oracle_04_存储过程,函数,触发器,索引,同义词
- Mybatis学习笔记-mybatis调用存储过程
- MYSQL学习笔记(十)存储过程(续)
- mysql学习笔记之十二(存储过程和函数)
- 35.Oracle深度学习笔记——关于dbms_shared_pool. MARKHOT
- NetTiers学习笔记05---使用自定义存储过程
- 【数据库学习笔记】MySQL_03_存储过程,触发器,权限,视图,函数
- (学习笔记)DBMS
- Oracle数据库学习笔记之异常处理,存储过程
- mysql笔记四——TEXT、LOB类型的使用和存储过程的使用
- 黑马程序员之C#学习笔记:后台C#调用存储过程
- Derby-10.11学习笔记(三)Derby系统表及存储过程
- PHP学习笔记(九):substr、explode
- SQL Server2000视图、存储过程、触发器学习笔记