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>
61 lines
8.1 KiB
HTML
61 lines
8.1 KiB
HTML
<a name="dli_spark_instr"></a><a name="dli_spark_instr"></a>
|
|
|
|
<h1 class="topictitle1">instr</h1>
|
|
<div id="body8662426"><p id="dli_spark_instr__en-us_topic_0000001696219549_p158837516483">This function is used to return the index of substr that appears earliest in str.</p>
|
|
<p id="dli_spark_instr__en-us_topic_0000001696219549_p18471163815215">It returns <strong id="dli_spark_instr__en-us_topic_0000001696219549_b1899622813917">NULL</strong> if either of the arguments are <strong id="dli_spark_instr__en-us_topic_0000001696219549_b1999710282919">NULL</strong> and returns <strong id="dli_spark_instr__en-us_topic_0000001696219549_b129983284916">0</strong> if substr does not exist in str. Note that the first character in str has index 1.</p>
|
|
<p id="dli_spark_instr__en-us_topic_0000001696219549_p1256954583717">Similar function: <a href="dli_spark_instr1.html#dli_spark_instr1">instr1</a>. The <strong id="dli_spark_instr__en-us_topic_0000001696219549_b2557193101119">instr1</strong> function is used to calculate the position of the substring str2 in the string str1. The <strong id="dli_spark_instr__en-us_topic_0000001696219549_b157078861120">instr1</strong> function allows you to specify the start search position and the number of matching times.</p>
|
|
<div class="section" id="dli_spark_instr__en-us_topic_0000001696219549_section45291954203217"><h4 class="sectiontitle">Syntax</h4><pre class="screen" id="dli_spark_instr__en-us_topic_0000001696219549_screen10637184423619">instr(string <str>, string <substr>)</pre>
|
|
</div>
|
|
<div class="section" id="dli_spark_instr__en-us_topic_0000001696219549_section992014913317"><h4 class="sectiontitle">Parameters</h4>
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dli_spark_instr__en-us_topic_0000001696219549_table1829154762513" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Parameters</caption><thead align="left"><tr id="dli_spark_instr__en-us_topic_0000001696219549_row8830104792517"><th align="left" class="cellrowborder" valign="top" width="19.220000000000002%" id="mcps1.3.5.2.2.5.1.1"><p id="dli_spark_instr__en-us_topic_0000001696219549_p983074711252">Parameter</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="13.420000000000002%" id="mcps1.3.5.2.2.5.1.2"><p id="dli_spark_instr__en-us_topic_0000001696219549_p6830124732517">Mandatory</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="15.590000000000002%" id="mcps1.3.5.2.2.5.1.3"><p id="dli_spark_instr__en-us_topic_0000001696219549_p13318164512614">Type</p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="51.77%" id="mcps1.3.5.2.2.5.1.4"><p id="dli_spark_instr__en-us_topic_0000001696219549_p08301547132513">Description</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="dli_spark_instr__en-us_topic_0000001696219549_row138881330152418"><td class="cellrowborder" valign="top" width="19.220000000000002%" headers="mcps1.3.5.2.2.5.1.1 "><p id="dli_spark_instr__en-us_topic_0000001696219549_p16689132714493">str</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="13.420000000000002%" headers="mcps1.3.5.2.2.5.1.2 "><p id="dli_spark_instr__en-us_topic_0000001696219549_p1937912389241">Yes</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="15.590000000000002%" headers="mcps1.3.5.2.2.5.1.3 "><p id="dli_spark_instr__en-us_topic_0000001696219549_p183791038192411">STRING</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="51.77%" headers="mcps1.3.5.2.2.5.1.4 "><p id="dli_spark_instr__en-us_topic_0000001696219549_p99134255019">Target string to be searched for</p>
|
|
<p id="dli_spark_instr__en-us_topic_0000001696219549_p19379638122412">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_instr__en-us_topic_0000001696219549_row20280174932413"><td class="cellrowborder" valign="top" width="19.220000000000002%" headers="mcps1.3.5.2.2.5.1.1 "><p id="dli_spark_instr__en-us_topic_0000001696219549_p1197812363499">substr</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="13.420000000000002%" headers="mcps1.3.5.2.2.5.1.2 "><p id="dli_spark_instr__en-us_topic_0000001696219549_p1228018496242">Yes</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="15.590000000000002%" headers="mcps1.3.5.2.2.5.1.3 "><p id="dli_spark_instr__en-us_topic_0000001696219549_p122271530161316">STRING</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="51.77%" headers="mcps1.3.5.2.2.5.1.4 "><p id="dli_spark_instr__en-us_topic_0000001696219549_p1980795014507">Substring to be matched</p>
|
|
<p id="dli_spark_instr__en-us_topic_0000001696219549_p784415518499">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>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="dli_spark_instr__en-us_topic_0000001696219549_section210162513312"><h4 class="sectiontitle">Return Values</h4><p id="dli_spark_instr__en-us_topic_0000001696219549_p42871014516">The return value is of the BIGINT type.</p>
|
|
<div class="note" id="dli_spark_instr__en-us_topic_0000001696219549_note61422099395"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="dli_spark_instr__en-us_topic_0000001696219549_ul7614142011527"><li id="dli_spark_instr__en-us_topic_0000001696219549_li106146205528">If <strong id="dli_spark_instr__en-us_topic_0000001696219549_b855037191313">str2</strong> is not found in <strong id="dli_spark_instr__en-us_topic_0000001696219549_b1700798133">str1</strong>, <strong id="dli_spark_instr__en-us_topic_0000001696219549_b1094913416127">0</strong> is returned.</li><li id="dli_spark_instr__en-us_topic_0000001696219549_li46141320125219">If <strong id="dli_spark_instr__en-us_topic_0000001696219549_b12756191861314">str2</strong> is an empty string, the matching is always successful. For example, <strong id="dli_spark_instr__en-us_topic_0000001696219549_b46692397130">select instr('abc','');</strong> returns <strong id="dli_spark_instr__en-us_topic_0000001696219549_b18913174251316">1</strong>.</li><li id="dli_spark_instr__en-us_topic_0000001696219549_li16146209527">If the value of <strong id="dli_spark_instr__en-us_topic_0000001696219549_b93069983864219">str1</strong> or <strong id="dli_spark_instr__en-us_topic_0000001696219549_b152630053564219">str2</strong> is <strong id="dli_spark_instr__en-us_topic_0000001696219549_b173246478964219">NULL</strong>, <strong id="dli_spark_instr__en-us_topic_0000001696219549_b75408479864219">NULL</strong> is returned.</li></ul>
|
|
</div></div>
|
|
</div>
|
|
<div class="section" id="dli_spark_instr__en-us_topic_0000001696219549_section13277192233920"><h4 class="sectiontitle">Example Code</h4><ul id="dli_spark_instr__en-us_topic_0000001696219549_ul129915529527"><li id="dli_spark_instr__en-us_topic_0000001696219549_li1529911521521">Returns the position of character b in string abc. An example command is as follows:<p id="dli_spark_instr__en-us_topic_0000001696219549_p19645819164"><a name="dli_spark_instr__en-us_topic_0000001696219549_li1529911521521"></a><a name="en-us_topic_0000001696219549_li1529911521521"></a>The value <strong id="dli_spark_instr__en-us_topic_0000001696219549_b343873541114010">2</strong> is returned.</p>
|
|
<pre class="screen" id="dli_spark_instr__en-us_topic_0000001696219549_screen25815268614">select instr('abc', 'b');</pre>
|
|
</li><li id="dli_spark_instr__en-us_topic_0000001696219549_li62997521522">The value of any input parameter is <strong id="dli_spark_instr__en-us_topic_0000001696219549_b105180877363856">NULL</strong>. An example command is as follows:<p id="dli_spark_instr__en-us_topic_0000001696219549_p49538311613">The value <strong id="dli_spark_instr__en-us_topic_0000001696219549_b201076799131728">NULL</strong> is returned.</p>
|
|
<pre class="screen" id="dli_spark_instr__en-us_topic_0000001696219549_screen1177140962">select instr('abc', null)</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>
|
|
|