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>
81 lines
9.6 KiB
HTML
81 lines
9.6 KiB
HTML
<a name="dli_spark_instr1"></a><a name="dli_spark_instr1"></a>
|
|
|
|
<h1 class="topictitle1">instr1</h1>
|
|
<div id="body8662426"><p id="dli_spark_instr1__en-us_topic_0000001696219573_p1611917543309">This function is used to return the position of substring str2 in string str1.</p>
|
|
<p id="dli_spark_instr1__en-us_topic_0000001696219573_p88181152193413">Similar function: <a href="dli_spark_instr.html#dli_spark_instr">instr</a>. The <strong id="dli_spark_instr1__en-us_topic_0000001696219573_b6189112319119">instr</strong> function is used to return the index of substr that appears earliest in <strong id="dli_spark_instr1__en-us_topic_0000001696219573_b14244133111118">str</strong>. However, instr does not support specifying the start search position and matching times.</p>
|
|
<div class="section" id="dli_spark_instr1__en-us_topic_0000001696219573_section45291954203217"><h4 class="sectiontitle">Syntax</h4><pre class="screen" id="dli_spark_instr1__en-us_topic_0000001696219573_screen1164981619226">instr1(string <str1>, string <str2>[, bigint <start_position>[, bigint <nth_appearance>]])</pre>
|
|
</div>
|
|
<div class="section" id="dli_spark_instr1__en-us_topic_0000001696219573_section992014913317"><h4 class="sectiontitle">Parameters</h4>
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dli_spark_instr1__en-us_topic_0000001696219573_table1829154762513" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Parameters</caption><thead align="left"><tr id="dli_spark_instr1__en-us_topic_0000001696219573_row8830104792517"><th align="left" class="cellrowborder" valign="top" width="19.220000000000002%" id="mcps1.3.4.2.2.5.1.1"><p id="dli_spark_instr1__en-us_topic_0000001696219573_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_instr1__en-us_topic_0000001696219573_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_instr1__en-us_topic_0000001696219573_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_instr1__en-us_topic_0000001696219573_p08301547132513">Description</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="dli_spark_instr1__en-us_topic_0000001696219573_row2826191220118"><td class="cellrowborder" valign="top" width="19.220000000000002%" headers="mcps1.3.4.2.2.5.1.1 "><p id="dli_spark_instr1__en-us_topic_0000001696219573_p58771645125213">str1</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="13.420000000000002%" headers="mcps1.3.4.2.2.5.1.2 "><p id="dli_spark_instr1__en-us_topic_0000001696219573_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_instr1__en-us_topic_0000001696219573_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_instr1__en-us_topic_0000001696219573_p1492772216114">Target string to be searched for</p>
|
|
<p id="dli_spark_instr1__en-us_topic_0000001696219573_p026862711252">If the value is of the BIGINT, DOUBLE, DECIMAL, or DATETIME type, the value is implicitly converted to the STRING type for calculation. For other types of values, an error is reported.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_spark_instr1__en-us_topic_0000001696219573_row5164582117"><td class="cellrowborder" valign="top" width="19.220000000000002%" headers="mcps1.3.4.2.2.5.1.1 "><p id="dli_spark_instr1__en-us_topic_0000001696219573_p121641181215">str2</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="13.420000000000002%" headers="mcps1.3.4.2.2.5.1.2 "><p id="dli_spark_instr1__en-us_topic_0000001696219573_p16164884110">Yes</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="15.590000000000002%" headers="mcps1.3.4.2.2.5.1.3 "><p id="dli_spark_instr1__en-us_topic_0000001696219573_p19164198115">STRING</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="51.77%" headers="mcps1.3.4.2.2.5.1.4 "><p id="dli_spark_instr1__en-us_topic_0000001696219573_p383614211313">Substring to be matched</p>
|
|
<p id="dli_spark_instr1__en-us_topic_0000001696219573_p121642818116">If the value is of the BIGINT, DOUBLE, DECIMAL, or DATETIME type, the value is implicitly converted to the STRING type for calculation. For other types of values, an error is reported.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_spark_instr1__en-us_topic_0000001696219573_row69649111111"><td class="cellrowborder" valign="top" width="19.220000000000002%" headers="mcps1.3.4.2.2.5.1.1 "><p id="dli_spark_instr1__en-us_topic_0000001696219573_p79641911914">start_position</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="13.420000000000002%" headers="mcps1.3.4.2.2.5.1.2 "><p id="dli_spark_instr1__en-us_topic_0000001696219573_p1896415111515">No</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="15.590000000000002%" headers="mcps1.3.4.2.2.5.1.3 "><p id="dli_spark_instr1__en-us_topic_0000001696219573_p49645111118">BIGINT</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="51.77%" headers="mcps1.3.4.2.2.5.1.4 "><p id="dli_spark_instr1__en-us_topic_0000001696219573_p861212152116">Sequence number of the character in str1 the search starts from. The default start position is position 1 (position of the first character).</p>
|
|
<p id="dli_spark_instr1__en-us_topic_0000001696219573_p18241749210">If this parameter is set to a negative number, the search starts from the end to the beginning of the string, and the last character is <strong id="dli_spark_instr1__en-us_topic_0000001696219573_b11781162614296">-1</strong>.</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="dli_spark_instr1__en-us_topic_0000001696219573_row2964311816"><td class="cellrowborder" valign="top" width="19.220000000000002%" headers="mcps1.3.4.2.2.5.1.1 "><p id="dli_spark_instr1__en-us_topic_0000001696219573_p596431117114">nth_appearance</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="13.420000000000002%" headers="mcps1.3.4.2.2.5.1.2 "><p id="dli_spark_instr1__en-us_topic_0000001696219573_p139649111114">No</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="15.590000000000002%" headers="mcps1.3.4.2.2.5.1.3 "><p id="dli_spark_instr1__en-us_topic_0000001696219573_p596418114119">BIGINT</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="51.77%" headers="mcps1.3.4.2.2.5.1.4 "><p id="dli_spark_instr1__en-us_topic_0000001696219573_p1785511132120">Position of str2 that is matched for the nth_appearance time in str1.</p>
|
|
<p id="dli_spark_instr1__en-us_topic_0000001696219573_p596441112120">If the value is of another type or is less than or equal to 0, an error is reported.</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="dli_spark_instr1__en-us_topic_0000001696219573_section210162513312"><h4 class="sectiontitle">Return Values</h4><p id="dli_spark_instr1__en-us_topic_0000001696219573_p966916247215">The return value is of the BIGINT type.</p>
|
|
<div class="note" id="dli_spark_instr1__en-us_topic_0000001696219573_note1542519149539"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="dli_spark_instr1__en-us_topic_0000001696219573_ul15439543520"><li id="dli_spark_instr1__en-us_topic_0000001696219573_li184393432029">If <strong id="dli_spark_instr1__en-us_topic_0000001696219573_b206731545441311">str2</strong> is not found in <strong id="dli_spark_instr1__en-us_topic_0000001696219573_b29656840941311">str1</strong>, <strong id="dli_spark_instr1__en-us_topic_0000001696219573_b93633909241311">0</strong> is returned.</li><li id="dli_spark_instr1__en-us_topic_0000001696219573_li34398431523">If str2 is an empty string, the matching is always successful.</li><li id="dli_spark_instr1__en-us_topic_0000001696219573_li743916431925">If the value of <strong id="dli_spark_instr1__en-us_topic_0000001696219573_b3831205716349">str1</strong>, <strong id="dli_spark_instr1__en-us_topic_0000001696219573_b183575793414">str2</strong>, <strong id="dli_spark_instr1__en-us_topic_0000001696219573_b1754272923511">start_position</strong>, or <strong id="dli_spark_instr1__en-us_topic_0000001696219573_b933914313511">nth_appearance</strong> is <strong id="dli_spark_instr1__en-us_topic_0000001696219573_b384065716344">NULL</strong>, <strong id="dli_spark_instr1__en-us_topic_0000001696219573_b1284115712345">NULL</strong> is returned.</li></ul>
|
|
</div></div>
|
|
</div>
|
|
<div class="section" id="dli_spark_instr1__en-us_topic_0000001696219573_section13277192233920"><h4 class="sectiontitle">Example Code</h4><p id="dli_spark_instr1__en-us_topic_0000001696219573_p942410145716">The value <strong id="dli_spark_instr1__en-us_topic_0000001696219573_b52955733517">10</strong> is returned.</p>
|
|
<pre class="screen" id="dli_spark_instr1__en-us_topic_0000001696219573_screen1555572414716">select instr1('Tech on the net', 'h', 5, 1);</pre>
|
|
<p id="dli_spark_instr1__en-us_topic_0000001696219573_p1942410141075">The value <strong id="dli_spark_instr1__en-us_topic_0000001696219573_b1535866462114010">2</strong> is returned.</p>
|
|
<pre class="screen" id="dli_spark_instr1__en-us_topic_0000001696219573_screen14940122713718">select instr1('abc', 'b');</pre>
|
|
<p id="dli_spark_instr1__en-us_topic_0000001696219573_p2042411141776">The value <strong id="dli_spark_instr1__en-us_topic_0000001696219573_b1064811317365">NULL</strong> is returned.</p>
|
|
<pre class="screen" id="dli_spark_instr1__en-us_topic_0000001696219573_screen1715263315711">select instr('abc', null);</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>
|
|
|