forked from docs/doc-exports
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>
71 lines
9.5 KiB
HTML
71 lines
9.5 KiB
HTML
<a name="dli_spark_trim"></a><a name="dli_spark_trim"></a>
|
|
|
|
<h1 class="topictitle1">trim</h1>
|
|
<div id="body8662426"><p id="dli_spark_trim__en-us_topic_0000001648099166_p1611917543309">This function is used to remove characters from the left and right of <strong id="dli_spark_trim__en-us_topic_0000001648099166_b10236143211312">str</strong>.</p>
|
|
<ul id="dli_spark_trim__en-us_topic_0000001648099166_ul35691210203514"><li id="dli_spark_trim__en-us_topic_0000001648099166_li13569111011352">If <strong id="dli_spark_trim__en-us_topic_0000001648099166_b1722047316113515">trimChars</strong> is not specified, spaces are removed by default.</li><li id="dli_spark_trim__en-us_topic_0000001648099166_li6569610183510">If <strong id="dli_spark_trim__en-us_topic_0000001648099166_b4971956195314">trimChars</strong> is specified, the function removes the longest possible substring from both the left and right ends of <strong id="dli_spark_trim__en-us_topic_0000001648099166_b149985605319">str</strong> that consists of characters in the <strong id="dli_spark_trim__en-us_topic_0000001648099166_b010065695315">trimChars</strong> set.</li></ul>
|
|
<p id="dli_spark_trim__en-us_topic_0000001648099166_p167161339419">Similar functions:</p>
|
|
<ul id="dli_spark_trim__en-us_topic_0000001648099166_ul151387820415"><li id="dli_spark_trim__en-us_topic_0000001648099166_li13847522124416"><a href="dli_spark_ltrim.html#dli_spark_ltrim">ltrim</a>. This function is used to remove characters from the left of <strong id="dli_spark_trim__en-us_topic_0000001648099166_b16353044305258">str</strong>.</li><li id="dli_spark_trim__en-us_topic_0000001648099166_li987011128446"><a href="dli_spark_rtrim.html#dli_spark_rtrim">rtrim</a>. This function is used to remove characters from the right of <strong id="dli_spark_trim__en-us_topic_0000001648099166_b1358038041113747">str</strong>.</li></ul>
|
|
<div class="section" id="dli_spark_trim__en-us_topic_0000001648099166_section45291954203217"><h4 class="sectiontitle">Syntax</h4><pre class="screen" id="dli_spark_trim__en-us_topic_0000001648099166_screen1164981619226">trim([<trimChars>,]string <str>)</pre>
|
|
<p id="dli_spark_trim__en-us_topic_0000001648099166_p1421764013517">or</p>
|
|
<pre class="screen" id="dli_spark_trim__en-us_topic_0000001648099166_screen1913545013357">trim([BOTH] [<trimChars>] from <str>)</pre>
|
|
</div>
|
|
<div class="section" id="dli_spark_trim__en-us_topic_0000001648099166_section992014913317"><h4 class="sectiontitle">Parameters</h4>
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dli_spark_trim__en-us_topic_0000001648099166_table1829154762513" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Parameters</caption><thead align="left"><tr id="dli_spark_trim__en-us_topic_0000001648099166_row8830104792517"><th align="left" class="cellrowborder" valign="top" width="19.220000000000002%" id="mcps1.3.6.2.2.5.1.1"><p id="dli_spark_trim__en-us_topic_0000001648099166_p983074711252">Parameter</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="13.420000000000002%" id="mcps1.3.6.2.2.5.1.2"><p id="dli_spark_trim__en-us_topic_0000001648099166_p6830124732517">Mandatory</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="15.590000000000002%" id="mcps1.3.6.2.2.5.1.3"><p id="dli_spark_trim__en-us_topic_0000001648099166_p13318164512614">Type</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="51.77%" id="mcps1.3.6.2.2.5.1.4"><p id="dli_spark_trim__en-us_topic_0000001648099166_p08301547132513">Description</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="dli_spark_trim__en-us_topic_0000001648099166_row2826191220118"><td class="cellrowborder" valign="top" width="19.220000000000002%" headers="mcps1.3.6.2.2.5.1.1 "><p id="dli_spark_trim__en-us_topic_0000001648099166_p1382631201120">str</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="13.420000000000002%" headers="mcps1.3.6.2.2.5.1.2 "><p id="dli_spark_trim__en-us_topic_0000001648099166_p14826312111113">Yes</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="15.590000000000002%" headers="mcps1.3.6.2.2.5.1.3 "><p id="dli_spark_trim__en-us_topic_0000001648099166_p18826101211118">STRING</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="51.77%" headers="mcps1.3.6.2.2.5.1.4 "><p id="dli_spark_trim__en-us_topic_0000001648099166_p026862711252">String from which characters on both left and right are to be removed</p>
|
|
<p id="dli_spark_trim__en-us_topic_0000001648099166_p13281133143614">If the value is of the BIGINT, DECIMAL, DOUBLE, or DATETIME type, the value is implicitly converted to the STRING type for calculation.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_spark_trim__en-us_topic_0000001648099166_row16208657112420"><td class="cellrowborder" valign="top" width="19.220000000000002%" headers="mcps1.3.6.2.2.5.1.1 "><p id="dli_spark_trim__en-us_topic_0000001648099166_p1208357102419">trimChars</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="13.420000000000002%" headers="mcps1.3.6.2.2.5.1.2 "><p id="dli_spark_trim__en-us_topic_0000001648099166_p520885714241">No</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="15.590000000000002%" headers="mcps1.3.6.2.2.5.1.3 "><p id="dli_spark_trim__en-us_topic_0000001648099166_p920815572243">STRING</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="51.77%" headers="mcps1.3.6.2.2.5.1.4 "><p id="dli_spark_trim__en-us_topic_0000001648099166_p1320835742417">Characters to be removed</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="dli_spark_trim__en-us_topic_0000001648099166_section210162513312"><h4 class="sectiontitle">Return Values</h4><p id="dli_spark_trim__en-us_topic_0000001648099166_p19597125133617">The return value is of the STRING type.</p>
|
|
<div class="note" id="dli_spark_trim__en-us_topic_0000001648099166_note61422099395"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="dli_spark_trim__en-us_topic_0000001648099166_ul0723178183713"><li id="dli_spark_trim__en-us_topic_0000001648099166_li7723588371">If the value of <strong id="dli_spark_trim__en-us_topic_0000001648099166_b48885896243454">str</strong> is not of the STRING, BIGINT, DOUBLE, DECIMAL, or DATETIME type, an error is reported.</li><li id="dli_spark_trim__en-us_topic_0000001648099166_li272316819374">If the value of <strong id="dli_spark_trim__en-us_topic_0000001648099166_b56262475311404">str</strong> or <strong id="dli_spark_trim__en-us_topic_0000001648099166_b119126775311404">trimChars</strong> is <strong id="dli_spark_trim__en-us_topic_0000001648099166_b162498664411404">NULL</strong>, <strong id="dli_spark_trim__en-us_topic_0000001648099166_b192576794611404">NULL</strong> is returned.</li></ul>
|
|
</div></div>
|
|
</div>
|
|
<div class="section" id="dli_spark_trim__en-us_topic_0000001648099166_section13277192233920"><h4 class="sectiontitle">Example Code</h4><ul id="dli_spark_trim__en-us_topic_0000001648099166_ul17663739163720"><li id="dli_spark_trim__en-us_topic_0000001648099166_li1766383916374">Removes spaces on both left and right of the string <strong id="dli_spark_trim__en-us_topic_0000001648099166_b51213357373">yxabcxx</strong>. An example command is as follows:<p id="dli_spark_trim__en-us_topic_0000001648099166_p111623523311">The value <strong id="dli_spark_trim__en-us_topic_0000001648099166_b12269165843718">yxabcxx</strong> is returned.</p>
|
|
<pre class="screen" id="dli_spark_trim__en-us_topic_0000001648099166_screen176061257203112">select trim(' yxabcxx '); </pre>
|
|
<p id="dli_spark_trim__en-us_topic_0000001648099166_p16162175253111">It is equivalent to the following statement:</p>
|
|
<pre class="screen" id="dli_spark_trim__en-us_topic_0000001648099166_screen19621125113211">select trim(both from ' yxabcxx ');
|
|
select trim(from ' yxabcxx ');</pre>
|
|
</li><li id="dli_spark_trim__en-us_topic_0000001648099166_li252122734211">Removes all substrings from both the left and right ends of the string <strong id="dli_spark_trim__en-us_topic_0000001648099166_b970532695412">yxabcxx</strong> that consist of characters in the set <strong id="dli_spark_trim__en-us_topic_0000001648099166_b570714263547">xy</strong>.<p id="dli_spark_trim__en-us_topic_0000001648099166_p19143205364619">The function returns <strong id="dli_spark_trim__en-us_topic_0000001648099166_b1776019514544">Txyom</strong>, as any substring starting with <strong id="dli_spark_trim__en-us_topic_0000001648099166_b37615517543">x</strong> or <strong id="dli_spark_trim__en-us_topic_0000001648099166_b18762251185417">y</strong> from both the left and right ends is removed.</p>
|
|
<pre class="screen" id="dli_spark_trim__en-us_topic_0000001648099166_screen122968294716">select trim('xy', 'yxabcxx'); </pre>
|
|
<p id="dli_spark_trim__en-us_topic_0000001648099166_p10143115313469">It is equivalent to the following statement:</p>
|
|
<pre class="screen" id="dli_spark_trim__en-us_topic_0000001648099166_screen10951151024710">select trim(both 'xy' from 'yxabcxx'); </pre>
|
|
</li><li id="dli_spark_trim__en-us_topic_0000001648099166_li1752115276429">The value of the input parameter is <strong id="dli_spark_trim__en-us_topic_0000001648099166_b70611620643627">NULL</strong>. An example command is as follows:<p id="dli_spark_trim__en-us_topic_0000001648099166_p944911439327">The value <strong id="dli_spark_trim__en-us_topic_0000001648099166_b16478318396">NULL</strong> is returned.</p>
|
|
<pre class="screen" id="dli_spark_trim__en-us_topic_0000001648099166_screen78295316326">select trim(null);
|
|
select trim(null, 'yxabcxx');</pre>
|
|
</li></ul>
|
|
</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>
|
|
|