Oracle中instr和substr儲存過程詳解

2022-09-21 23:54:11 字數 2532 閱讀 4450

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函式用於從大物件中抽取指定數碼的位元組。當我們只需要大物件的一部分時,通常使用這個函式。

操作內部大物件的substrhmvqcx函式語法如下:

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 substringwww.cppcns.com 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中substr和instr的用法

網上蒐集的,整理下 1 substr string string,int a,int b 引數1 string 要處理的字串 引數2 a 擷取字串的開始位置 起始位置是0 引數3 b 擷取的字串的長度 而不是字串的結束位置 例如 substr abcdefg 0 返回 abcdefg,擷取所有字元 ...

Oracle中INSTR和SUBSTR的用法

oracle中instr和substr的用法 oracle中instr的用法 instr方法的格式為 instr 源字串,要查詢的字串,從第幾個字元開始,要找到第幾個匹配的序號 返回找到的位置,如果找不到則返回0.例如 instr corporate floor or 3,2 中,源字串為 corp...

Oracle中INSTR和SUBSTR的用法

oracle中instr和substr的用法 oracle中instr的用法 instr方法的格式為 instr 源字串,要查詢的字串,從第幾個字元開始,要找到第幾個匹配的序號 返回找到的位置,如果找不到則返回0.例如 instr corporate floor or 3,2 中,源字串為 corp...