我想从用substr从-001.00里面取到-1这个值,想请问下该怎么取。

解决方案 »

  1.   


    SQL> select substr(replace('-001.00','0',''),1,2) from dual;
     
    SUBSTR(REPLACE('-001.00'
    ------------------------
    -1
      

  2.   


    SQL> select trunc(-001.00,0)+10 from dual;
     
    TRUNC(-001.00,0)+10
    -------------------
                      9
     
    SQL> select substr(replace('-001.00','0',''),1,2)+10 sum from dual;
     
           SUM
    ----------
             9
      

  3.   


    SQL> select trunc(-001.00) from dual;
     
    TRUNC(-001.00)
    --------------
                -1
    oracle trunc for number
      

  4.   

    楼上的大哥能解释下细节么,或者给我个substr的语法给我看看,我想活用下这个,一时间找不到数看,我只想取第一个字节和第四个字节,还有能告诉我下载SQL脚本里面+001SQL能识别成1不,-001能识别成-1不
      

  5.   

    In Oracle/PLSQL, the substr functions allows you to extract a substring from a string.The syntax for the substr function is:substr( string, start_position, [ length ] )string is the source string.start_position is the position for extraction.
    The first position in the string is always 1.
    length is optional. It is the number of characters to extract. 
    If this parameter is omitted, substr will return the entire string.
    Note:If start_position is 0, then substr treats start_position as 1 
    (ie: the first position in the string).If start_position is a positive number, then substr starts from the beginning of the string.
    If start_position is a negative number, then substr starts from the end of the string and 
    counts backwards.
    If length is a negative number, then substr will return a NULL value.Applies To:Oracle 8i, Oracle 9i, Oracle 10g, Oracle 11gFor example:substr('This is a test', 6, 2) would return 'is'
    substr('This is a test', 6) would return 'is a test'
    substr('TechOnTheNet', 1, 4) would return 'Tech'
    substr('TechOnTheNet', -3, 3) would return 'Net'
    substr('TechOnTheNet', -6, 3) would return 'The'
    substr('TechOnTheNet', -8, 2) would return 'On'
      

  6.   

    如果是取前三个字符应该怎么做啊,哥哥姐姐们,麻烦告诉下,小弟回家就去网上钻研几天ORACLE去,现在初学急用,请各位哥哥姐姐帮衬下
      

  7.   

    多谢学友大哥,我基本上了解了substr的大概用法了,请问下SQL里面+01和是不是和1一样都会被识别为1啊