zoukankan      html  css  js  c++  java
  • sql中字符串连接

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

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

    CONCAT() 的语法如下:CONCAT(字串1, 字串2, 字串3, ...): 将字串1、字串2、字串3,等字串连在一起。请注意,Oracle的CONCAT()只允许两个参数;换言之,一次只能将两个字串串连起来。不过,在Oracle中,我们可以用'||'来一次串连多个字串。

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

    Geography 表格

    region_namestore_name
    EastBoston
    EastNew York
    WestLos Angeles
    WestSan 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_name FROM Geography

    WHERE store_name = 'Boston'; 
  • 相关阅读:
    Python从文件中读取数据
    Python中类的继承
    Python中的类(2)
    Python中的类
    自动登陆抽屉(1)
    爬取汽车之家新闻
    Django简介
    web应用,http协议简介,web框架
    CentOS7安装python3.6
    MySQL之索引
  • 原文地址:https://www.cnblogs.com/peijie-tech/p/3443928.html
Copyright © 2011-2022 走看看