• Oracle函数--合并,替换,拼接,截取,查找


    1.合并函数 wm_concat(column)
    wm_concat(列名),该函数可以把列值以“,”号分隔起来,并显示成一行。如果列值是中文的,则选择另一种方式: wm_concat(to_char(列名))

    例如下面例子:

    执行下面SQL:select id,wm_concat(to_char(name)) name from testTable group by id; 可得到下面结果

    2.替换函数 replace(原字段,“原字段旧内容“,“原字段新内容“,)

     执行下面SQL:select id,name,replace(num,'10','5') num0 from testTable ;  可得到下面结果

    3.拼接字符串函数concat(字串1, 字串2

    对于字符串拼接,每一种资料库都有戏相应方法-----MySQL: CONCAT()      Oracle: CONCAT(), ||      SQL Server: +

    CONCAT() 的语法如下:CONCAT(字串1, 字串2, 字串3, ...): 将字串1、字串2、字串3,等字串连在一起。但是,Oracle的CONCAT()只允许两个参数,如要拼接多个参数则嵌套使用concat可实现,或者可以使用“||”来拼接 !!!

    执行下面SQL:1)select name || '(' || num || '斤)' as str from testTable ; 

                          2)select concat(name, '(' || num || '斤)') as str from testTable ;可得到下面结果

    4.截取字符串函数substr(字符串,截取开始位置,截取长度)

     执行下面SQL:  select substr(name,0,1) str from testTable; 可得到下面结果

    5.查找函数INSTR(string,subString,position,ocurrence)查找字符串位置

    该函数可以用于模糊查询以及判断包含关系:

    例如:1) select id,name ,num from testTable where instr(name,'香蕉')>0;

    等同于  select id,name ,num from testTable where name like '%香蕉%';

              2)  select id,name ,num from testTable where instr('123,香蕉',name)>0;

    等同于  select id,name ,num from testTable where name in ('123,香蕉');

     

  • 相关阅读:
    Spring RestController @RequestParam 中的 required=false 参数
    unity中动画状态机(Animator)介绍
    unity音效
    unity2019中播放动画循环
    unity2019自定义天空盒
    unity脚本物体移动,旋转,属性可见性
    选择排序
    es 深度分页查询
    windows关闭防火墙和病毒程序软件步骤
    信息整理
  • 原文地址:https://www.cnblogs.com/mcahkf/p/7156668.html
Copyright © 2020-2023  润新知