• SQL— CONCAT(字符串连接函数)


    有的时候,我们有需要将由不同栏位获得的资料串连在一起。每一种资料库都有提供方法来达到这个目的:

    • MySQL: CONCAT()
    • Oracle: CONCAT(), ||
    • SQL Server: +

    CONCAT() 的语法如下:

    CONCAT(字串1, 字串2, 字串3,...): 将字串1、字串2、字串3,等字串连在一起。

    请注意,Oracle的CONCAT()只允许两个参数;

    换言之,一次只能将两个字串串连起来。不过,在Oracle中,我们可以用'||'来一次串连多个字串。

    来看几个例子。假设我们有以下的表格:

    Geography 表格

    region_name store_name
    East Boston
    East New York
    West Los Angeles
    West San Diego

    例子1:

    MySQL/Oracle:
    SELECT CONCAT(region_name,store_name)FROM Geography
    WHERE store_name = 'Boston';

    结果

    'EastBoston'

    例子2:

    Oracle:
    SELECT region_name || ' ' ||store_name FROM Geography
    WHERE store_name = 'Boston';

    结果

    'East Boston'

    例子3:

    SQL Server:
    SELECT region_name + ' ' + store_nameFROM Geography
    WHERE store_name = 'Boston';

    结果

    'East Boston'

    分享:
  • 相关阅读:
    CoreData数据库浅析
    FMDB第三方框架
    SQLite浅析
    iOS开发工程师面试题(二)
    iOS开发工程师面试题(一)
    RunTime&RunLoop初见
    GCD定时器
    2016年4月21百度iOS实习生在线笔试题&编程题
    网络天荒地老之UIWebView&WebKit
    expdp/impdp
  • 原文地址:https://www.cnblogs.com/baobeiqi-e/p/9884781.html
Copyright © 2020-2023  润新知