Oracle,Postgres和SQL Server中的字符串连接运算符 [英] String concatenation operator in Oracle, Postgres and SQL Server

查看:310
本文介绍了Oracle,Postgres和SQL Server中的字符串连接运算符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有一种方法可以在Oracle,Postgres和SQL Server中连接一个公共运算符。



在Oracle中,我们使用'|',postgres使用'|| '和'sql server使用'+'。



我已经通过添加自定义运算符'+'支持字符串连接解决了postgres中的问题。



有一种方法可以在Oracle中添加相同的操作符,以支持使用+运算符的字符串连接。

解决方案

|| 是SQL标准连接运算符(请参阅SQL 2008:5.2)。使用它,如果它在您使用的系统中不起作用,则抱怨; - )



但是,严重的是,你应该让其他系统使用 || ,而不是 + 。不仅是更标准,但是如果你使用 + ,更容易意外造成混乱,特别是如果任何类型必须被推断或隐式强制转换。



请考虑:'5'+ 2



你使用的不会抛出一个错误,并且 + 意味着加和连接,你可能会在一些混乱的结果。


Is there a way to have a common operator for concatenation in Oracle, Postgres and SQL Server.

In Oracle we uses '|', postgres uses '||' and sql server uses '+'.

I've solved the problem in postgres by adding the custom operator '+' to support string concatenation.

Is there a way to add the same operator in Oracle to support string concatenation using the '+' operator.

解决方案

|| is the SQL Standard concatenation operator (see SQL 2008: 5.2). Use that, and complain if it doesn't work in the system you're using ;-)

Seriously though, you should make other systems use ||, not +. Not only is it more standard, but it's easier to accidentally cause confusion if you use +, especially if any types have to be inferred or and implicit casts are happening.

Consider: '5' + 2

If the system you're using doesn't throw an error on that one, and + means both plus and concatenation, you might be in for some confusing results.

这篇关于Oracle,Postgres和SQL Server中的字符串连接运算符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆