Oracle中instr和substr存儲過程詳解

instr和substr存儲過程,分析內部大對象的內容

instr函數文章源自四五設計網-http://www.wasochina.com/44024.html

instr函數用于從指定的位置開始,從大型對象中查找第N個與模式匹配的字符串。文章源自四五設計網-http://www.wasochina.com/44024.html

用于查找內部大對象中的字符串的instr函數語法如下:文章源自四五設計網-http://www.wasochina.com/44024.html

1
2
3
4
5
6
7
8
9
10
11
12
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為內部大對象的定位器文章源自四五設計網-http://www.wasochina.com/44024.html

pattern是要匹配的模式文章源自四五設計網-http://www.wasochina.com/44024.html

offset是要搜索匹配文件的開始位置文章源自四五設計網-http://www.wasochina.com/44024.html

nth是要進行的第N次匹配文章源自四五設計網-http://www.wasochina.com/44024.html

?substr函數文章源自四五設計網-http://www.wasochina.com/44024.html

substr函數用于從大對象中抽取指定數碼的字節。當我們只需要大對象的一部分時,通常使用這個函數。文章源自四五設計網-http://www.wasochina.com/44024.html

操作內部大對象的substr函數語法如下:文章源自四五設計網-http://www.wasochina.com/44024.html

1
2
3
4
5
6
7
8
9
10
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

示例如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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存儲過程詳解,希望對大家有所幫助

繼續閱讀
我的微信
微信掃一掃
weinxin
我的微信
惠生活福利社
微信掃一掃
weinxin
我的公眾號
 
  • 本文由 四五設計網小助手 發表于 2024年3月29日10:29:59
  • 轉載請務必保留本文鏈接:http://www.wasochina.com/44024.html

發表評論

匿名網友
:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

拖動滑塊以完成驗證