`

oracle substr、instr

 
阅读更多

substr

  Oracle中的截取字符串函数。

  语法如下:

  substr( string, start_position, [ length ] )

  参数分析:

  string

  字符串值

  start_position

  截取字符串的初始位置, Number型,start_position为负数时,表示从字符串右边数起。

  length

  截取位数,Number型

  其中,length为可选,如果length为空(即不填)则返回start_position后面的所有字符。

  意思就是:

  从start_position开始,取出length个字符并返回取出的字符串。

  具体参考示例。

  示例:

  SELECT  substr('This is a test', 6, 2)  FROM dual        返回 'is'

  substr('SyranMo have a dream', -8, 2)

instr
    INSTR(C1,C2,I,J)
    在一个字符串中搜索指定的字符,返回发现指定的字符的位置;
    C1 被搜索的字符串
    C2 希望搜索的字符串
    I 搜索的开始位置,默认为1
    J 出现的位置,默认为1
    SQL> select instr(’oracle traning’,’ra’,1,2) instring from dual;
    意识是从’oracle traning’里面查找ra第二次出现的位置。。。
    显示结果为
    INSTRING
    ---------
    9
    oracle里超过4000字的文本一般都放在clob里面(sql里面放在text)
    里面,现在oracle里面对大字段不支持where字句like直接操作,
    虽然可以用select语句直接查询出大字段来查看,但因为字段太大,
    可以用instr来查询看返回的结果
    表结构:
    create table products(
    productid number(10) not null ,
    name varchar2(255) ,
    description CLOB) ;

    方法:
    SELECT productid, name FROM products
    WHERE dbms_lob.instr(products.description,'some text',1,1) > 0;
 

 

 

分享到:
评论
1 楼 三市白衣 2012-08-16  
Select Substring(@S1,CHARINDEX('www',@S1)+1,Len(@S1)) 为什么要+1?

相关推荐

Global site tag (gtag.js) - Google Analytics