SQL 标量函数-----> 取子串函数 、子串长度

    技术2022-05-20  57

     

     

    一、Left()函数用法、len()函数用法

     

           1. unitCode, unitName插入dimUnit.

     

           Insert into dimUnit(unitCode,parentUnitCode,unitName)

           select unitcode as unitCode, '',unitname as unitName

           from ZC_Unit

            order by unitcode

            2.parentUnitCode进行赋值

     

             update dimUnit set parentUnitCode=left(unitcode,2)

             where len(unitcode)>2

     

          3.select unitcode as unitCode, left(unitcode,2)as parentUnitCode,unitname as unitName

            from ZC_Unit

            order by unitcode

     

     

     

     

     

    //

     

     取子串函数

    1、left()

    LEFT (, )

    返回character_expression 左起 integer_expression 个字符。

    2、RIGHT()

    RIGHT (, )

    返回character_expression 右起 integer_expression 个字符。

    3、SUBSTRING()

    SUBSTRING (, , length)

    返回从字符串左边第starting_ position 个字符起length个字符的部分。

     

    执行:

     

    select substring('abcde',2,3)select left('abcde',4)select right('abcde',3)

     


    最新回复(0)