MySQL SQL 选择符号 || 是什么意思 意思?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/23372550/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-31 20:28:18  来源:igfitidea点击:

What does SQL Select symbol || mean?

mysqlsqloracleansi-sql

提问by collapsar

What does ||do in SQL?

||在 SQL中做什么?

SELECT 'a' || ',' || 'b' AS letter

回答by collapsar

||represents string concatenation. Unfortunately, string concatenation is not completely portable across all sql dialects:

||表示字符串连接。不幸的是,字符串连接在所有 sql 方言中都不是完全可移植的:

  • ansi sql: ||(infix operator)
  • mysql: concat( vararg function ). caution: ||means 'logical or' (It's configurable, however; thanks to @hvdfor pointing that out)
  • oracle: ||(infix operator), concat( caution: function of arity 2 only ! )
  • postgres: ||(infix operator)
  • sql server: +(infix operator), concat( vararg function )
  • sqlite: ||(infix operator)
  • ansi sql: ||(中缀运算符)
  • mysql:(concat可变参数函数)。注意||表示“逻辑或”(但是,它是可配置的;感谢@hvd指出这一点)
  • oracle:(中||缀运算符),concat注意:仅 arity 2 的函数!)
  • postgres:(中 ||缀运算符)
  • sql server: +(中缀运算符), concat(可变参数函数)
  • sqlite:(中||缀运算符)

hopefully the confusion is complete ...

希望混乱是完整的......

回答by John Hartsock

It is a concat statement. It will concatenate the two strings.

这是一个 concat 语句。它将连接两个字符串。

Here is a helpful post!

这是一个有用的帖子!

What is the difference between "||" operator and concat function in Oracle?

"||" 和有什么不一样 Oracle 中的运算符和 concat 函数?

回答by ivanprakasa

SELECT 'a' || ',' || 'b' AS letter will combine a letter. The result become 'a,b'

选择'a' || ',' || 'b' AS 字母将组合一个字母。结果变成'a,b'

回答by Andrew

It's a concatenation operator. So you would get 'a,b' from that. I think ||will work on mostRDBMS's. SQL Server requires the +operator (thanks to HVD for setting me straight!).

这是一个连接运算符。所以你会得到'a,b'。我认为||将适用于大多数RDBMS。SQL Server 需要+操作员(感谢 HVD 让我直截了当!)。

回答by SQLMason

In Oracle, SQLite3, and MySQL, it concatenates strings. Please see the Oracle documentation. The MySQL documentation.

在 Oracle、SQLite3 和 MySQL 中,它连接字符串。请参阅Oracle 文档。在MySQL文档

Also, it's part of ANSI SQL, but read this for more information.

此外,它是 ANSI SQL 的一部分,但请阅读本文以获取更多信息

回答by Jonathan