doc-exports/docs/dli/sqlreference/dli_spark_conv.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

76 lines
8.4 KiB
HTML

<a name="dli_spark_conv"></a><a name="dli_spark_conv"></a>
<h1 class="topictitle1">conv</h1>
<div id="body8662426"><p id="dli_spark_conv__en-us_topic_0000001696282261_p18471163815215">This function is used to convert a number from <strong id="dli_spark_conv__en-us_topic_0000001696282261_b569013555911">from_base</strong> to <strong id="dli_spark_conv__en-us_topic_0000001696282261_b1369114555916">to_base</strong>.</p>
<div class="section" id="dli_spark_conv__en-us_topic_0000001696282261_section45291954203217"><h4 class="sectiontitle">Syntax</h4><pre class="screen" id="dli_spark_conv__en-us_topic_0000001696282261_screen19928459112517">conv(BIGINT num, INT from_base, INT to_base)</pre>
</div>
<div class="section" id="dli_spark_conv__en-us_topic_0000001696282261_section992014913317"><h4 class="sectiontitle">Parameters</h4>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="dli_spark_conv__en-us_topic_0000001696282261_table1829154762513" frame="border" border="1" rules="all"><caption><b>Table 1 </b>Parameters</caption><thead align="left"><tr id="dli_spark_conv__en-us_topic_0000001696282261_row8830104792517"><th align="left" class="cellrowborder" valign="top" width="19.220000000000002%" id="mcps1.3.3.2.2.5.1.1"><p id="dli_spark_conv__en-us_topic_0000001696282261_p983074711252">Parameter</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="13.44%" id="mcps1.3.3.2.2.5.1.2"><p id="dli_spark_conv__en-us_topic_0000001696282261_p6830124732517">Mandatory</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="15.57%" id="mcps1.3.3.2.2.5.1.3"><p id="dli_spark_conv__en-us_topic_0000001696282261_p13318164512614">Type</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="51.77%" id="mcps1.3.3.2.2.5.1.4"><p id="dli_spark_conv__en-us_topic_0000001696282261_p08301547132513">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="dli_spark_conv__en-us_topic_0000001696282261_row15830184792511"><td class="cellrowborder" valign="top" width="19.220000000000002%" headers="mcps1.3.3.2.2.5.1.1 "><p id="dli_spark_conv__en-us_topic_0000001696282261_p683034714250">num</p>
</td>
<td class="cellrowborder" valign="top" width="13.44%" headers="mcps1.3.3.2.2.5.1.2 "><p id="dli_spark_conv__en-us_topic_0000001696282261_p12830184752518">Yes</p>
</td>
<td class="cellrowborder" valign="top" width="15.57%" headers="mcps1.3.3.2.2.5.1.3 "><p id="dli_spark_conv__en-us_topic_0000001696282261_p0318545102615">DOUBLE, BIGINT, DECIMAL, or STRING</p>
</td>
<td class="cellrowborder" valign="top" width="51.77%" headers="mcps1.3.3.2.2.5.1.4 "><p id="dli_spark_conv__en-us_topic_0000001696282261_p26541229175815">Number whose base needs to be converted</p>
<p id="dli_spark_conv__en-us_topic_0000001696282261_p39997321521">The value can be a float, integer, or string.</p>
</td>
</tr>
<tr id="dli_spark_conv__en-us_topic_0000001696282261_row07891045114711"><td class="cellrowborder" valign="top" width="19.220000000000002%" headers="mcps1.3.3.2.2.5.1.1 "><p id="dli_spark_conv__en-us_topic_0000001696282261_p117902045184714">from_base</p>
</td>
<td class="cellrowborder" valign="top" width="13.44%" headers="mcps1.3.3.2.2.5.1.2 "><p id="dli_spark_conv__en-us_topic_0000001696282261_p107902045204711">Yes</p>
</td>
<td class="cellrowborder" valign="top" width="15.57%" headers="mcps1.3.3.2.2.5.1.3 "><p id="dli_spark_conv__en-us_topic_0000001696282261_p0790184511477">DOUBLE, BIGINT, DECIMAL, or STRING</p>
</td>
<td class="cellrowborder" valign="top" width="51.77%" headers="mcps1.3.3.2.2.5.1.4 "><p id="dli_spark_conv__en-us_topic_0000001696282261_p179017452477">It represents the base from which the number is converted.</p>
<p id="dli_spark_conv__en-us_topic_0000001696282261_p0706195414913">The value can be a float, integer, or string.</p>
</td>
</tr>
<tr id="dli_spark_conv__en-us_topic_0000001696282261_row102756584816"><td class="cellrowborder" valign="top" width="19.220000000000002%" headers="mcps1.3.3.2.2.5.1.1 "><p id="dli_spark_conv__en-us_topic_0000001696282261_p12275459481">to_base</p>
</td>
<td class="cellrowborder" valign="top" width="13.44%" headers="mcps1.3.3.2.2.5.1.2 "><p id="dli_spark_conv__en-us_topic_0000001696282261_p227518520485">Yes</p>
</td>
<td class="cellrowborder" valign="top" width="15.57%" headers="mcps1.3.3.2.2.5.1.3 "><p id="dli_spark_conv__en-us_topic_0000001696282261_p82757514816">DOUBLE, BIGINT, DECIMAL, or STRING</p>
</td>
<td class="cellrowborder" valign="top" width="51.77%" headers="mcps1.3.3.2.2.5.1.4 "><p id="dli_spark_conv__en-us_topic_0000001696282261_p10275851481">It represents the base to which the number is converted.</p>
<p id="dli_spark_conv__en-us_topic_0000001696282261_p53996381199">The value can be a float, integer, or string.</p>
</td>
</tr>
</tbody>
</table>
</div>
</div>
<div class="section" id="dli_spark_conv__en-us_topic_0000001696282261_section210162513312"><h4 class="sectiontitle">Return Values</h4><p id="dli_spark_conv__en-us_topic_0000001696282261_p184124317231">The return value is of the STRING type.</p>
<div class="note" id="dli_spark_conv__en-us_topic_0000001696282261_note61422099395"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="dli_spark_conv__en-us_topic_0000001696282261_ul16692738406"><li id="dli_spark_conv__en-us_topic_0000001696282261_li1261324216015">If the value of <strong id="dli_spark_conv__en-us_topic_0000001696282261_b142412279243">num</strong>, <strong id="dli_spark_conv__en-us_topic_0000001696282261_b6241227162410">from_base</strong>, or <strong id="dli_spark_conv__en-us_topic_0000001696282261_b224827182415">to_base</strong> is <strong id="dli_spark_conv__en-us_topic_0000001696282261_b132410279246">NULL</strong>, <strong id="dli_spark_conv__en-us_topic_0000001696282261_b3251027112419">NULL</strong> is returned.</li><li id="dli_spark_conv__en-us_topic_0000001696282261_li27876441604">The conversion process works with 64-bit precision and returns <strong id="dli_spark_conv__en-us_topic_0000001696282261_b7325172252617">NULL</strong> when there is overflow.</li><li id="dli_spark_conv__en-us_topic_0000001696282261_li86925381507">If the value of <strong id="dli_spark_conv__en-us_topic_0000001696282261_b167981533142610">num</strong> is a decimal, it will be converted to an integer before the base conversion, and the decimal part will be discarded.</li></ul>
</div></div>
</div>
<div class="section" id="dli_spark_conv__en-us_topic_0000001696282261_section13277192233920"><h4 class="sectiontitle">Example Code</h4><p id="dli_spark_conv__en-us_topic_0000001696282261_p2141731114816">The value <strong id="dli_spark_conv__en-us_topic_0000001696282261_b1620231422912">8</strong> is returned.</p>
<pre class="screen" id="dli_spark_conv__en-us_topic_0000001696282261_screen2172135314912">select conv('1000', 2, 10);</pre>
<p id="dli_spark_conv__en-us_topic_0000001696282261_p1310763344817">The value <strong id="dli_spark_conv__en-us_topic_0000001696282261_b198103576298">B</strong> is returned.</p>
<pre class="screen" id="dli_spark_conv__en-us_topic_0000001696282261_screen54146315020">select conv('1011', 2, 16);</pre>
<p id="dli_spark_conv__en-us_topic_0000001696282261_p1074573413483">The value <strong id="dli_spark_conv__en-us_topic_0000001696282261_b113128146308">703710</strong> is returned.</p>
<pre class="screen" id="dli_spark_conv__en-us_topic_0000001696282261_screen1476231112509">select conv('ABCDE', 16, 10);</pre>
<p id="dli_spark_conv__en-us_topic_0000001696282261_p13191153617486">The value <strong id="dli_spark_conv__en-us_topic_0000001696282261_b81211521143013">27</strong> is returned.</p>
<pre class="screen" id="dli_spark_conv__en-us_topic_0000001696282261_screen568542365010">select conv(1000.123456, 3.123456, 10.123456);</pre>
<p id="dli_spark_conv__en-us_topic_0000001696282261_p25329399487">The value <strong id="dli_spark_conv__en-us_topic_0000001696282261_b37291331193011">18446744073709551589</strong> is returned.</p>
<pre class="screen" id="dli_spark_conv__en-us_topic_0000001696282261_screen18358334175019">select conv(-1000.123456, 3.123456, 10.123456);</pre>
<p id="dli_spark_conv__en-us_topic_0000001696282261_p1063344111484">The value <strong id="dli_spark_conv__en-us_topic_0000001696282261_b1390383853016">NULL</strong> is returned.</p>
<pre class="screen" id="dli_spark_conv__en-us_topic_0000001696282261_screen8497194955018">select conv('1100', null, 10);</pre>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dli_08_0473.html">Mathematical Functions</a></div>
</div>
</div>