数据库操作(四)、标量函数

标量函数

  1、大写:upper();

        select upper(列名) from 表名;

  2、小写:lower();

        select lower(列名) from 表名;

  3、截取字符串:substring();

        select substring(列名,从谁开始,截取几个) from 表名;

  4、指定字符串的起始位置:charindex();

        select charindex('值1',列名,从几开始) from 表名;

                 '值1':找谁     列名:从哪找

        select charindex(列名1,列名2,截取几个) from 表名;

                 两列相比

      也可写在where条件中使其语句有意义:select * from 表名 where charindex(列名1,列名2,截取几个)>0;

  5、打印长度,去首尾空格len();

        select len(列名) from 表名;

  6、去掉左边空格打印值,ltrim();

        select ltrim(列名) from 表名;

     去掉右边空格打印值,rtrim();

         select rtrim(列名) from 表名;

  7、从列最左边开始截取值:left();

           select left(列名,截取几个) from 表名;

    从列的最右边开始截取值:right();  

        select right(列名,截取几个) from 表名;

  8、取空值:isnull(); 

        select isnull(列名,'xx') from 表名;

       注:若xx为空,则打印空

       

        

原文地址:https://www.cnblogs.com/Yida-Tingting/p/4434935.html