如何从clob列中获取一个特定的字符串?
我有如下数据,它存储在名为product_details的clob列中
CALCULATION=[N]NEW.PRODUCT_NO=[T9856] OLD.PRODUCT_NO=[T9852].... -- with other text
我想从列product_details搜索字符串NEW.PRODUCT_NO
我试过了
select * from my_table where dbms_lob.instr(product_details,'NEW.PRODUCT_NO')>=1
以上从表中获取全文.
任何帮助都是非常可观的.
问候
解决方法
使用
dbms_lob.instr和
dbms_lob.substr,就像常规的InStr和SubstStr功能一样.
看简单的例子:
看简单的例子:
sql> create table t_clob( 2 id number,3 cl clob 4 ); Tabela zosta│a utworzona. sql> insert into t_clob values ( 1,' xxxx abcd xyz qwerty 354657 [] ' ); 1 wiersz zosta│ utworzony. sql> declare 2 i number; 3 begin 4 for i in 1..400 loop 5 update t_clob set cl = cl || ' xxxx abcd xyz qwerty 354657 [] '; 6 end loop; 7 update t_clob set cl = cl || ' CALCULATION=[N]NEW.PRODUCT_NO=[T9856] OLD.PRODUCT_NO=[T9852].... -- with other text '; 8 for i in 1..400 loop 9 update t_clob set cl = cl || ' xxxx abcd xyz qwerty 354657 [] '; 10 end loop; 11 end; 12 / Procedura PL/sql zosta│a zako˝czona pomyťlnie. sql> commit; Zatwierdzanie zosta│o uko˝czone. sql> select length( cl ) from t_clob; LENGTH(CL) ---------- 25717 sql> select dbms_lob.instr( cl,'NEW.PRODUCT_NO=[' ) from t_clob; DBMS_LOB.INSTR(CL,'NEW.PRODUCT_NO=[') ------------------------------------- 12849 sql> select dbms_lob.substr( cl,5,dbms_lob.instr( cl,'NEW.PRODUCT_NO=[' ) + length( 'NEW.PRODUCT_NO=[') ) new_product 2 from t_clob; NEW_PRODUCT -------------------------------------------------------------------------------- T9856