一个字段,比如3行内容分别为:“aabdd”,“abec”,“aqccbdf”。现在我想截取“b”之前的内容,请问该怎么做?substr()函数好象要指定截取的位置,但在这个字段中“b”的位置不是固定的。

解决方案 »

  1.   

    SQL> select * from test_1;COL1       COL2       COL3
    ---------- ---------- ----
    A          B          1000
    A          C          1100
    A          D           900
    A          E           400
    B          D           300
    D          F           600
    E          A           400
    F          G          1000
    C          B           600
    1                     
    1                     11 行 已选择SQL> select substr(to_char(col3),1,instr(to_char(col3),'0',1)-1)   as sub from test_1;SUB
    --------------------------------------------------------------------------------
    1
    11
    9
    4
    3
    6
    4
    1
    611 行 已选择
      

  2.   

    请问楼上的,能说说instr()函数的参数是怎么定义的和功能吗?我如果要取第二个“0”前的字符串呢?
      

  3.   

    instr()函数的用法见:
    http://www.netbox.cn/document/html/vsfctinstr.htm
      

  4.   

    substr()  和 instr() 一起用