Oracle中instr和substr存储过程详解

所属分类: 数据库 / oracle 阅读数: 1451
收藏 0 赞 0 分享

instr和substr存储过程,分析内部大对象的内容

instr函数

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 过程已成功完成。

以上所述是小编给大家介绍的Oracle中instr和substr存储过程详解,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对脚本之家网站的支持!

更多精彩内容其他人还在看

oracle存储过程中return和exit区别概述及测试

至于return和exit在oracle存储过程中的应用,有些新手朋友们还是比较容易混淆的,本文将针对这两个关键字进行详细对比下,感兴趣的你可以参考下,希望可以帮助到你
收藏 0 赞 0 分享

oracle查看当前日期是第几个星期的方法

oracle查看当前日期是第几个星期方法的代码段,需要的朋友可以参考一下
收藏 0 赞 0 分享

oracle删除已存在的表的实例

查询系统表,判断表是否存在,存在则直接删除
收藏 0 赞 0 分享

oracle中文乱码解决的办法

oracle中文乱码解决的办法,需要的朋友可以参考一下
收藏 0 赞 0 分享

Oracle中在pl/sql developer修改表的2种方法

Oracle中在pl/sql developer修改表的2种方法,需要的朋友可以参考一下
收藏 0 赞 0 分享

oracle 创建表空间步骤代码

oracle 创建表空间步骤代码,需要的朋友可以参考一下
收藏 0 赞 0 分享

Oracle 查看表空间的大小及使用情况sql语句

表空间使用情况包括:查看表空间的名称及大小/查看表空间物理文件的名称及大小/查看回滚段名称及大小等等感兴趣的你可以参考下本文
收藏 0 赞 0 分享

Oracle Form中COMMIT的概述及使用技巧

针对form上面的数据变动提交到后台数据库,同时数据库提交数据,接下来将详细介绍下Form中COMMIT的使用,感兴趣的你可以参考下本文
收藏 0 赞 0 分享

Oracle跨数据库查询并插入实现原理及代码

需要从一个数据库中的表GIS_WEICHAI_DATA_1S中的数据导入到另个一数据库的表GIS_WEICHAI_DATA_1S中,接下来为你讲解跨数据库查询并插入需要的朋友可以参考下
收藏 0 赞 0 分享

Oracle 存储过程发送邮件实例学习

接下来将介绍下如何使用存储过程发送邮件这一案例实现,感兴趣的你可以参考下本文或许对你有所帮助
收藏 0 赞 0 分享
查看更多