doc-exports/docs/dli/sqlreference/dli_spark_replace.html
Su, Xiaomeng 76a5b1ee83 dli_sqlreference_20240227
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: Su, Xiaomeng <suxiaomeng1@huawei.com>
Co-committed-by: Su, Xiaomeng <suxiaomeng1@huawei.com>
2024-03-27 22:02:33 +00:00

66 lines
6.4 KiB
HTML

<a name="dli_spark_replace"></a><a name="dli_spark_replace"></a>
<h1 class="topictitle1">replace</h1>
<div id="body8662426"><p id="dli_spark_replace__en-us_topic_0000001647939930_p1662914651016">This function is used to replace the part in a specified string that is the same as the string <strong id="dli_spark_replace__en-us_topic_0000001647939930_b08021535183814">old</strong> with the string new and return the result.</p>
<p id="dli_spark_replace__en-us_topic_0000001647939930_p1611917543309">If the string has no same characters as the string <strong id="dli_spark_replace__en-us_topic_0000001647939930_b1229454493916">old</strong>, <strong id="dli_spark_replace__en-us_topic_0000001647939930_b1521095712393">str</strong> is returned.</p>
<div class="section" id="dli_spark_replace__en-us_topic_0000001647939930_section45291954203217"><h4 class="sectiontitle">Syntax</h4><pre class="screen" id="dli_spark_replace__en-us_topic_0000001647939930_screen1164981619226">replace(string &lt;str&gt;, string &lt;old&gt;, string &lt;new&gt;)</pre>
</div>
<div class="section" id="dli_spark_replace__en-us_topic_0000001647939930_section992014913317"><h4 class="sectiontitle">Parameters</h4>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dli_spark_replace__en-us_topic_0000001647939930_table1829154762513" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Parameters</caption><thead align="left"><tr id="dli_spark_replace__en-us_topic_0000001647939930_row8830104792517"><th align="left" class="cellrowborder" valign="top" width="19.220000000000002%" id="mcps1.3.4.2.2.5.1.1"><p id="dli_spark_replace__en-us_topic_0000001647939930_p983074711252">Parameter</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="13.420000000000002%" id="mcps1.3.4.2.2.5.1.2"><p id="dli_spark_replace__en-us_topic_0000001647939930_p6830124732517">Mandatory</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="15.590000000000002%" id="mcps1.3.4.2.2.5.1.3"><p id="dli_spark_replace__en-us_topic_0000001647939930_p13318164512614">Type</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="51.77%" id="mcps1.3.4.2.2.5.1.4"><p id="dli_spark_replace__en-us_topic_0000001647939930_p08301547132513">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="dli_spark_replace__en-us_topic_0000001647939930_row2826191220118"><td class="cellrowborder" valign="top" width="19.220000000000002%" headers="mcps1.3.4.2.2.5.1.1 "><p id="dli_spark_replace__en-us_topic_0000001647939930_p58771645125213">str</p>
</td>
<td class="cellrowborder" valign="top" width="13.420000000000002%" headers="mcps1.3.4.2.2.5.1.2 "><p id="dli_spark_replace__en-us_topic_0000001647939930_p14826312111113">Yes</p>
</td>
<td class="cellrowborder" valign="top" width="15.590000000000002%" headers="mcps1.3.4.2.2.5.1.3 "><p id="dli_spark_replace__en-us_topic_0000001647939930_p18826101211118">STRING</p>
</td>
<td class="cellrowborder" valign="top" width="51.77%" headers="mcps1.3.4.2.2.5.1.4 "><p id="dli_spark_replace__en-us_topic_0000001647939930_p026862711252">String to be replaced</p>
</td>
</tr>
<tr id="dli_spark_replace__en-us_topic_0000001647939930_row440811711119"><td class="cellrowborder" valign="top" width="19.220000000000002%" headers="mcps1.3.4.2.2.5.1.1 "><p id="dli_spark_replace__en-us_topic_0000001647939930_p15408371114">old</p>
</td>
<td class="cellrowborder" valign="top" width="13.420000000000002%" headers="mcps1.3.4.2.2.5.1.2 "><p id="dli_spark_replace__en-us_topic_0000001647939930_p17436103312118">Yes</p>
</td>
<td class="cellrowborder" valign="top" width="15.590000000000002%" headers="mcps1.3.4.2.2.5.1.3 "><p id="dli_spark_replace__en-us_topic_0000001647939930_p943623313111">STRING</p>
</td>
<td class="cellrowborder" valign="top" width="51.77%" headers="mcps1.3.4.2.2.5.1.4 "><p id="dli_spark_replace__en-us_topic_0000001647939930_p1140847161111">String to be compared</p>
</td>
</tr>
<tr id="dli_spark_replace__en-us_topic_0000001647939930_row32894561111"><td class="cellrowborder" valign="top" width="19.220000000000002%" headers="mcps1.3.4.2.2.5.1.1 "><p id="dli_spark_replace__en-us_topic_0000001647939930_p72891757111">new</p>
</td>
<td class="cellrowborder" valign="top" width="13.420000000000002%" headers="mcps1.3.4.2.2.5.1.2 "><p id="dli_spark_replace__en-us_topic_0000001647939930_p399710331116">Yes</p>
</td>
<td class="cellrowborder" valign="top" width="15.590000000000002%" headers="mcps1.3.4.2.2.5.1.3 "><p id="dli_spark_replace__en-us_topic_0000001647939930_p799713338116">STRING</p>
</td>
<td class="cellrowborder" valign="top" width="51.77%" headers="mcps1.3.4.2.2.5.1.4 "><p id="dli_spark_replace__en-us_topic_0000001647939930_p328911511118">String after replacement</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="dli_spark_replace__en-us_topic_0000001647939930_section210162513312"><h4 class="sectiontitle">Return Values</h4><p id="dli_spark_replace__en-us_topic_0000001647939930_p551845187">The return value is of the STRING type.</p>
<div class="note" id="dli_spark_replace__en-us_topic_0000001647939930_note1542519149539"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="dli_spark_replace__en-us_topic_0000001647939930_p9273175141110">If the value of any input parameter is <strong id="dli_spark_replace__en-us_topic_0000001647939930_b94831059124015">NULL</strong>, <strong id="dli_spark_replace__en-us_topic_0000001647939930_b14483185914404">NULL</strong> is returned.</p>
</div></div>
</div>
<div class="section" id="dli_spark_replace__en-us_topic_0000001647939930_section13277192233920"><h4 class="sectiontitle">Example Code</h4><p id="dli_spark_replace__en-us_topic_0000001647939930_p143526018186">The value <strong id="dli_spark_replace__en-us_topic_0000001647939930_b6162132019415">AA123AA</strong> is returned.</p>
<pre class="screen" id="dli_spark_replace__en-us_topic_0000001647939930_screen1268081213184">select replace('abc123abc','abc','AA');</pre>
<p id="dli_spark_replace__en-us_topic_0000001647939930_p43528020183">The value <strong id="dli_spark_replace__en-us_topic_0000001647939930_b452093117416">NULL</strong> is returned.</p>
<pre class="screen" id="dli_spark_replace__en-us_topic_0000001647939930_screen175503189188">select replace('abc123abc',null,'AA');</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dli_08_0472.html">String Functions</a></div>
</div>
</div>