Files
doc-exports/docs/dws/tool/DWS_DS_67.html
Lu, Huayi 4194b50d78 DWS TOOL 811 version
Reviewed-by: Hasko, Vladimir <vladimir.hasko@t-systems.com>
Co-authored-by: Lu, Huayi <luhuayi@huawei.com>
Co-committed-by: Lu, Huayi <luhuayi@huawei.com>
2022-12-14 20:46:26 +00:00

42 lines
9.6 KiB
HTML

<a name="EN-US_TOPIC_0000001145913101"></a><a name="EN-US_TOPIC_0000001145913101"></a>
<h1 class="topictitle1">Executing a Function/Procedure</h1>
<div id="body32001227"><p id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_p42941906">After you connect to the database, all the stored functions/procedures and tables will be automatically populated in the <strong id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_b1047692">Object Browser</strong> pane. You can use Data Studio to execute PL/SQL programs or SQL functions.</p>
<div class="note" id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_note50932842"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><ul id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_ul9429236"><li id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_li22309582">Blank lines occurring above or below in a function/procedure will be trimmed by Data Studio before being sent to the server. Blank lines will also be trimmed when displaying the source received from the server.</li><li id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_li66568510">To execute a function/procedure, enter the same values in Data Studio and the <strong id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_b5149608914253">gsql </strong>client. If you do not enter any value in Data Studio, then <strong id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_b148411548576">NULL</strong> is considered as the input.<p id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_p28809145">For example:</p>
<p id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_p51839388">- To execute the function/procedure with string, enter the value as <em id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_i6896979151421">data</em>.</p>
<p id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_p63901309">- To execute the function/procedure with date, enter the value as <em id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_i18304283151413">to_date('2012-10-10', 'YYYY-MM-DD').</em></p>
</li><li id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_li11511003">A function/procedure with OUT and INOUT parameter types cannot be executed directly.</li><li id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_li36490171">Data Studio will not execute any function/procedure with unknown data type parameters.</li></ul>
</div></div>
<p id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_p18840050">You can right-click the function/procedure in the <strong id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_b59984603">Object Browser</strong> to perform the following operations:</p>
<ul id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_ul35342723"><li id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_li2913837">Refresh the program to get the latest program from the server.</li><li id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_li26224539">Execute the function/procedure or SQL function.</li><li id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_li34694260">Debug the PL/SQL function.</li><li id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_li43812891">Drop the debug object.</li></ul>
<div class="section" id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_section143275198410"><h4 class="sectiontitle">How to Execute a PL/SQL Program or SQL Function?</h4><p id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_p39258096173114">Follow the steps below to execute a PL/SQL program or SQL function:</p>
<ol id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_ol62887584"><li id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_li29117349"><span>Double-click and open the PL/SQL program or SQL function. Each debug object will be opened in a new tab. You can open a maximum of 100 tabs in Data Studio.</span></li><li id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_li60729557"><span>Click <span><img id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_image32530274" src="figure/en-us_image_0000001145913273.png" width="15.96" height="15.96" title="Click to enlarge" class="imgResize"></span> in the toolbar, or choose <strong id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_b24337017">Run &gt; Execute DB Object</strong> from the main menu, or right-click the program name in the<strong id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_b17706563"> Object Browser</strong> and select <strong id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_b25141347">Execute</strong>.</span><p><p id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_p24945537">Alternatively, you can right-click in the <strong id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_b23183246">PL/SQL</strong> <strong id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_b37814045184023">Viewer</strong> tab and select <strong id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_b45079717184054">Execute</strong>.</p>
</p></li><li id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_li25532096"><span>The <strong id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_b170955315936">Execute Function/Procedure</strong> dialog box is displayed prompting for your input.</span><p><div class="note" id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_note56261938"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p class="text" id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_p36595397">If there is no input parameter, then the <strong id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_b64772850151036">Execute Function/Procedure </strong>dialog box will not appear. Instead, the PL/SQL program will execute and the result (if any) will be displayed in the <strong id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_b11437218">Result</strong> tab.</p>
</div></div>
</p></li><li id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_li32441571"><span>Provide your input for the function/procedure in the <strong id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_b11879716">Execute PL/pgSQL</strong> dialog box and click <strong id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_b42752621184146">OK</strong>.</span><p><p id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_p22732954">To set NULL as the parameter value, enter <strong id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_b1815761065810">NULL </strong>or <strong id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_b926361616587">null</strong>.</p>
<ul id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_ul63543344"><li id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_li19813363">If you do not provide a value that starts with a single quote, then a single quote (') will be added by Data Studio before and after the value and typecasting is done.</li><li id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_li44102542">If you provide a value that starts with a single quote, an additional single quote will not be added by Data Studio, but data type typecasting is done.<p id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_p10910688152633"><a name="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_li44102542"></a><a name="en-us_topic_0185264330_li44102542"></a>For example:</p>
<p id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_p17982255">For supported data types, the execution queries are as follows:</p>
<pre class="screen" id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_screen17549981124451">select func('1'::INTEGER);
select func('1'::FLOAT);
select func('xyz'::VARCHAR);</pre>
</li><li id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_li61370790">If quotes are already provided, you need to take care of escaping the quotes.<p id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_p2367800315270"><a name="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_li61370790"></a><a name="en-us_topic_0185264330_li61370790"></a>For example:</p>
<p id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_p4178072">If the input value is <em id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_i2879553">ab'c</em>, then you need to enter<em id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_i25915985"> ab''c</em>.</p>
</li></ul>
<p id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_p14912646175450">The PL/SQL program is executed in the <strong id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_b50743455191324">SQL Terminal</strong> tab and the result is displayed in the <strong id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_b48027136">Result</strong> tab. You can copy the contents of the <strong id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_b64992778">Result</strong> tab by clicking <span><img id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_image3935007819323" src="figure/en-us_image_0000001098833308.jpg" width="15.96" height="15.96" title="Click to enlarge" class="imgResize"></span>. Refer to <a href="DWS_DS_128.html">Using SQL Terminals</a> for more information on toolbar options.</p>
<p id="EN-US_TOPIC_0000001145913101__en-us_topic_0185264330_p2083484812362">Refer to <a href="DWS_DS_128.html#EN-US_TOPIC_0000001145833051__en-us_topic_0185264856_section16147111413113">Executing SQL Queries</a> section for information on reconnect option in case connection is lost during execution.</p>
</p></li></ol>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="DWS_DS_60.html">Working with Functions/Procedures</a></div>
</div>
</div>
<script language="JavaScript">
<!--
image_size('.imgResize');
var msg_imageMax = "view original image";
var msg_imageClose = "close";
//--></script>