doc-exports/docs/dws/dev/dws_04_0552.html
Lu, Huayi e6fa411af0 DWS DEV 830.201 version
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com>
Co-authored-by: Lu, Huayi <luhuayi@huawei.com>
Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
2024-05-16 07:24:04 +00:00

99 lines
10 KiB
HTML

<a name="EN-US_TOPIC_0000001233681769"></a><a name="EN-US_TOPIC_0000001233681769"></a>
<h1 class="topictitle1">DBMS_RANDOM</h1>
<div id="body8662426"><div class="section" id="EN-US_TOPIC_0000001233681769__sff1277ad4ade4e56b62abea7ea8498e2"><h4 class="sectiontitle">Related Interfaces</h4><p id="EN-US_TOPIC_0000001233681769__aef8e2b9f6fe349619d1e77b01f4696a8"><a href="#EN-US_TOPIC_0000001233681769__t8a5bcdf2282f4e64a850b8ae4a7f7076">Table 1</a> provides all interfaces supported by the <strong id="EN-US_TOPIC_0000001233681769__b119271102041228">DBMS_RANDOM</strong> package.</p>
<div class="tablenoborder"><a name="EN-US_TOPIC_0000001233681769__t8a5bcdf2282f4e64a850b8ae4a7f7076"></a><a name="t8a5bcdf2282f4e64a850b8ae4a7f7076"></a><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001233681769__t8a5bcdf2282f4e64a850b8ae4a7f7076" frame="border" border="1" rules="all"><caption><b>Table 1 </b>DBMS_RANDOM interface parameters</caption><thead align="left"><tr id="EN-US_TOPIC_0000001233681769__r9dd1fbf03c464acb874efe9dc0054127"><th align="left" class="cellrowborder" valign="top" width="44.45%" id="mcps1.3.1.3.2.3.1.1"><p id="EN-US_TOPIC_0000001233681769__a8e85b20fa43646159c57bbce19598b13">Interface</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="55.55%" id="mcps1.3.1.3.2.3.1.2"><p id="EN-US_TOPIC_0000001233681769__aca5ba8ef41934e84b7265ef7160c60a0">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="EN-US_TOPIC_0000001233681769__rebf96530b1324abca840038222b104ff"><td class="cellrowborder" valign="top" width="44.45%" headers="mcps1.3.1.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001233681769__a8b0235fe51c744658f28aa7c1b3b8b5e">DBMS_RANDOM.SEED</p>
</td>
<td class="cellrowborder" valign="top" width="55.55%" headers="mcps1.3.1.3.2.3.1.2 "><p id="EN-US_TOPIC_0000001233681769__a07cc984494434d22b93d683fdde44758">Sets a seed for a random number.</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001233681769__r81824f231f9744be9ff7cd4d887ebdb8"><td class="cellrowborder" valign="top" width="44.45%" headers="mcps1.3.1.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001233681769__a31bcde4d02a94616ae52f03bf4a4973e">DBMS_RANDOM.VALUE</p>
</td>
<td class="cellrowborder" valign="top" width="55.55%" headers="mcps1.3.1.3.2.3.1.2 "><p id="EN-US_TOPIC_0000001233681769__a51f82158e1a74d60947e2632c81ce419">Generates a random number between a specified low and a specified high.</p>
</td>
</tr>
</tbody>
</table>
</div>
<ul id="EN-US_TOPIC_0000001233681769__ua1cecbb5b6b34f6ba76fd6ec483c384d"><li id="EN-US_TOPIC_0000001233681769__l4aad3da7b38a4442af63e28faf51e0ba">DBMS_RANDOM.SEED<p id="EN-US_TOPIC_0000001233681769__a7c897f398e754a688e106fefa0d4f6ee"><a name="EN-US_TOPIC_0000001233681769__l4aad3da7b38a4442af63e28faf51e0ba"></a><a name="l4aad3da7b38a4442af63e28faf51e0ba"></a>The stored procedure SEED is used to set a seed for a random number. The DBMS_RANDOM.SEED function prototype is:</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001233681769__sc79b820dcf0e4f9698a8a32f22842342"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="n">DBMS_RANDOM</span><span class="p">.</span><span class="n">SEED</span><span class="w"> </span><span class="p">(</span><span class="n">seed</span><span class="w"> </span><span class="k">IN</span><span class="w"> </span><span class="nb">INTEGER</span><span class="p">);</span>
</pre></div></td></tr></table></div>
</div>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001233681769__t6e87b64d358a494ca20dc7ba56499e00" frame="border" border="1" rules="all"><caption><b>Table 2 </b>DBMS_RANDOM.SEED interface parameters</caption><thead align="left"><tr id="EN-US_TOPIC_0000001233681769__r5f2274277ce345e2b04aab2c2b34d27f"><th align="left" class="cellrowborder" valign="top" width="25.28%" id="mcps1.3.1.4.1.3.2.3.1.1"><p id="EN-US_TOPIC_0000001233681769__ae2dac93bd7804fc7a398756001a6b4d1">Parameter</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="74.72%" id="mcps1.3.1.4.1.3.2.3.1.2"><p id="EN-US_TOPIC_0000001233681769__aed419bec3cae4ae59fcfd626e533e862">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="EN-US_TOPIC_0000001233681769__r1ce592a41a8f44538aebea21d112251d"><td class="cellrowborder" valign="top" width="25.28%" headers="mcps1.3.1.4.1.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001233681769__a89da09eb6b6240e787db085a80e471aa">seed</p>
</td>
<td class="cellrowborder" valign="top" width="74.72%" headers="mcps1.3.1.4.1.3.2.3.1.2 "><p id="EN-US_TOPIC_0000001233681769__a739597952bfa4a07aa4384005a939d5c">Generates a seed for a random number.</p>
</td>
</tr>
</tbody>
</table>
</div>
</li></ul>
<ul id="EN-US_TOPIC_0000001233681769__u126b148a7f364b8e957bcc5752ebf744"><li id="EN-US_TOPIC_0000001233681769__l605ebfc282024f8e8c0c32fc70b7bb67">DBMS_RANDOM.VALUE<p id="EN-US_TOPIC_0000001233681769__a23cb9d983e8c4e08a15f2d8f18914250"><a name="EN-US_TOPIC_0000001233681769__l605ebfc282024f8e8c0c32fc70b7bb67"></a><a name="l605ebfc282024f8e8c0c32fc70b7bb67"></a>The stored procedure VALUE generates a random number between a specified low and a specified high. The DBMS_RANDOM.VALUE function prototype is:</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001233681769__sb93dae7f3e1b469887026ca45c594059"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span>
<span class="normal">2</span>
<span class="normal">3</span>
<span class="normal">4</span></pre></div></td><td class="code"><div><pre><span></span><span class="n">DBMS_RANDOM</span><span class="p">.</span><span class="n">VALUE</span><span class="p">(</span>
<span class="n">low</span><span class="w"> </span><span class="k">IN</span><span class="w"> </span><span class="nb">NUMBER</span><span class="p">,</span>
<span class="n">high</span><span class="w"> </span><span class="k">IN</span><span class="w"> </span><span class="nb">NUMBER</span><span class="p">)</span>
<span class="k">RETURN</span><span class="w"> </span><span class="nb">NUMBER</span><span class="p">;</span>
</pre></div></td></tr></table></div>
</div>
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001233681769__tbc7b7ba3e2c946d8acfbcaf3cee52865" frame="border" border="1" rules="all"><caption><b>Table 3 </b>DBMS_RANDOM.VALUE interface parameters</caption><thead align="left"><tr id="EN-US_TOPIC_0000001233681769__r54101b121f504c2289cd5b137315d66d"><th align="left" class="cellrowborder" valign="top" width="15.06%" id="mcps1.3.1.5.1.3.2.3.1.1"><p id="EN-US_TOPIC_0000001233681769__a08b9fd33e4e3413f85e7caedba9d07c0">Parameter</p>
</th>
<th align="left" class="cellrowborder" valign="top" width="84.94%" id="mcps1.3.1.5.1.3.2.3.1.2"><p id="EN-US_TOPIC_0000001233681769__a0bded07e2cde4045b491f7edd6f95732">Description</p>
</th>
</tr>
</thead>
<tbody><tr id="EN-US_TOPIC_0000001233681769__r9db223386ac2445dae91ec8f7fdaf983"><td class="cellrowborder" valign="top" width="15.06%" headers="mcps1.3.1.5.1.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001233681769__a5ec64e2efc3e40f99c9db70b9ce5b41b">low</p>
</td>
<td class="cellrowborder" valign="top" width="84.94%" headers="mcps1.3.1.5.1.3.2.3.1.2 "><p id="EN-US_TOPIC_0000001233681769__a2ca10d3f91a4442c8b68f9ca75fad05f">Sets the low bound for a random number. The generated random number is greater than or equal to the low.</p>
</td>
</tr>
<tr id="EN-US_TOPIC_0000001233681769__rd655979d7a0c4ef18517048156de376b"><td class="cellrowborder" valign="top" width="15.06%" headers="mcps1.3.1.5.1.3.2.3.1.1 "><p id="EN-US_TOPIC_0000001233681769__ad39220449d834d6ab488b2bf2ef6dcbb">high</p>
</td>
<td class="cellrowborder" valign="top" width="84.94%" headers="mcps1.3.1.5.1.3.2.3.1.2 "><p id="EN-US_TOPIC_0000001233681769__aea0d175505504145835c7b88e4d454de">Sets the high bound for a random number. The generated random number is less than the high.</p>
</td>
</tr>
</tbody>
</table>
</div>
</li></ul>
<div class="note" id="EN-US_TOPIC_0000001233681769__ne33476a44a994df5b412580d97bdaca1"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001233681769__a23f04720b6be4d7fb45766ce6b7b6f54">The only requirement is that the parameter type is <strong id="EN-US_TOPIC_0000001233681769__en-us_topic_0027042974_b1591162165239">NUMERIC</strong> regardless of the right and left bound values.</p>
</div></div>
</div>
<div class="section" id="EN-US_TOPIC_0000001233681769__s079477904afe4e6889d1db09d6c14d21"><h4 class="sectiontitle">Example</h4><p id="EN-US_TOPIC_0000001233681769__a79cf218b33034f9fabc89c773b753271">Generate a random number between 0 and 1.</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001233681769__screen4341154103216"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="n">DBMS_RANDOM</span><span class="p">.</span><span class="n">VALUE</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">1</span><span class="p">);</span>
</pre></div></td></tr></table></div>
</div>
<p id="EN-US_TOPIC_0000001233681769__p1154131015329">Specify the low and high parameters to an integer within the specified range and intercept smaller values from the result. (The maximum value cannot be a possible value.) Therefore, use the following code for an integer between 0 and 99:</p>
<div class="codecoloring" codetype="Sql" id="EN-US_TOPIC_0000001233681769__screen31012393320"><div class="highlight"><table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><span class="normal">1</span></pre></div></td><td class="code"><div><pre><span></span><span class="k">SELECT</span><span class="w"> </span><span class="n">TRUNC</span><span class="p">(</span><span class="n">DBMS_RANDOM</span><span class="p">.</span><span class="n">VALUE</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span><span class="mi">100</span><span class="p">));</span>
</pre></div></td></tr></table></div>
</div>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_04_0550.html">Advanced Packages</a></div>
</div>
</div>