The mysterious string concatenation operator in Oracle
All programming languages require a way to concatenate string values, and Oracle SQL is no exception. But in the world of Oracle, what is the mysterious operator that performs this task?
Secret: || String concatenation
Oracle string concatenation operator is '||' (two vertical bars). This humble symbol allows you to seamlessly concatenate string values, as in the following example:
<code class="language-sql">select 'Mr ' || ename from emp;</code>
An interesting feature: embracing the unexpected
While '||' does its job well, it does have an "interesting" property. When concatenating a string with a null value, the result is surprisingly the original string itself, not null. This behavior may lead to unexpected results, so be careful when handling null values.
Summary
Although the string concatenation operator in Oracle may seem simple, it has a subtle feature that may catch you off guard. Keep in mind that '||' handles null values differently than you expect; it preserves the original string. Armed with this knowledge, you can confidently take advantage of the power of string concatenation in Oracle and avoid any unexpected pitfalls.
The above is the detailed content of What's the Oracle SQL String Concatenation Operator and How Does it Handle NULL Values?. For more information, please follow other related articles on the PHP Chinese website!