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

来源:互联网 发布:深圳大数据协会 编辑:程序博客网 时间:2024/05/01 08:39

 

 

一、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 setparentUnitCode=left(unitcode,2)

         where len(unitcode)>2

 

      3.select unitcode as unitCode, left(unitcode,2)as parentUnitCode,unitnameas 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个字符的部分。

 

执行:

 

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

 

原创粉丝点击