zoukankan      html  css  js  c++  java
  • MySQL字符串处理函数的几种常见用法

    1.字符串大小写转化:

    (1).将tbl_student表的user_name字段所有小写字母,替换为大写:

         update tbl_student set user_name=UPPER(user_name);

    (2).将tbl_student表的user_name字段所有大写字母,替换成小写:

    update tbl_student set user_name=LOWER(user_name);

    2.清除字符串首尾空格,或者指定字符:

    (1).清除tbl_student表的user_name字段首尾空格

         update tbl_student set user_name=TRIM(' ' from user_name);

    (2).清除字符串首部指定字符A:

        update tbl_student set user_name=TRIM(LEADING 'A' from user_name);

    (3).清除字符串尾部指定字符B

          update tbl_student set user_name=trim(TRAILING 'B' from user_name);

    3.替换字符串:

    (1).替换字符串中的数字1为字母I

         update tbl_student set user_name=replace(user_name,'1','I');

    4.用正则(REGEXP):

    (1).若结尾两个为字母,则去掉

         update tbl_student stu stu.user_name=substring(stu.user_name,LENGTH(stu.user_name)-2) where stu.user_name REGEXP '[a-zA-Z]{2,}$';

  • 相关阅读:
    POJ3984-迷宫问题【BFS】
    BFS与DFS模板
    nyoj27-水池数目【DFS】
    C++ STL-stack使用详解
    C++ STL
    HDU1058
    HDU1114
    HDU1867
    Codeforces Round #461 (Div. 2) D. Robot Vacuum Cleaner
    Codeforces Round #461 (Div. 2) C. Cave Painting
  • 原文地址:https://www.cnblogs.com/chunyansong/p/5868719.html
Copyright © 2011-2022 走看看