doc-exports/docs/dws/dev/dws_04_0520.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

27 lines
4.5 KiB
HTML

<a name="EN-US_TOPIC_0000001233761687"></a><a name="EN-US_TOPIC_0000001233761687"></a>
<h1 class="topictitle1">Basic Structure</h1>
<div id="body8662426"><div class="section" id="EN-US_TOPIC_0000001233761687__s2043f4ccca7b4cd9baa561e1eb5264ce"><h4 class="sectiontitle">Structure</h4><p id="EN-US_TOPIC_0000001233761687__a30eb8f1e079742d28c2f88e5f31eb893">A PL/SQL block can contain a sub-block which can be placed in any section. The following describes the architecture of a PL/SQL block:</p>
<ul id="EN-US_TOPIC_0000001233761687__ub4a8bec09e9546d998db00732fe4f15c"><li id="EN-US_TOPIC_0000001233761687__lc329dcb04c4a4f2d8c947c1459ea095d"><strong id="EN-US_TOPIC_0000001233761687__b842352706115848">DECLARE</strong>: declares variables, types, cursors, and regional stored procedures and functions used in the PL/SQL block.<pre class="screen" id="EN-US_TOPIC_0000001233761687__s4dfc68ef92aa4589a0737e5595aea3cc">DECLARE</pre>
<div class="note" id="EN-US_TOPIC_0000001233761687__nde3e75179edc4a898ca0b89e5a94d372"><img src="public_sys-resources/note_3.0-en-us.png"><span class="notetitle"> </span><div class="notebody"><p id="EN-US_TOPIC_0000001233761687__a6efa2635e9134da9b9acbeadcaaceff8">This part is optional if no variable needs to be declared.</p>
<ul id="EN-US_TOPIC_0000001233761687__u8d7997e1502c4d0cbc6fb32bea7344bc"><li id="EN-US_TOPIC_0000001233761687__l89e5baa9c2454c0db3908be555e207d3">An anonymous block may omit the <strong id="EN-US_TOPIC_0000001233761687__a42e105897a3d454385e5f058ac06a8dc">DECLARE</strong> keyword if no variable needs to be declared.</li><li id="EN-US_TOPIC_0000001233761687__l1abf5f3c5bdb4c34bc0dd2861dc86331">For a stored procedure, <strong id="EN-US_TOPIC_0000001233761687__a324700f3558e46968c942a709e60b90b">AS</strong> is used, which is equivalent to <strong id="EN-US_TOPIC_0000001233761687__a029a25c2d507469dae4f7f98e90bca33">DECLARE</strong>. The <strong id="EN-US_TOPIC_0000001233761687__a17c1750dc7904f7d9a27fbc432b1292e">AS</strong> keyword must be reserved even if there is no variable declaration part.</li></ul>
</div></div>
</li><li id="EN-US_TOPIC_0000001233761687__l8563d8b280424efd948d99e3f0f3f93c"><strong id="EN-US_TOPIC_0000001233761687__b842352706115912">EXECUTION</strong>: specifies procedure and SQL statements. It is the main part of a program. Mandatory<pre class="screen" id="EN-US_TOPIC_0000001233761687__s0a43446cdfa94a0aa764fcdcda1b3351">BEGIN</pre>
</li><li id="EN-US_TOPIC_0000001233761687__lec9aaefe621244f2a6821d09413a7d38"><strong id="EN-US_TOPIC_0000001233761687__b84235270611591">EXCEPTION</strong>: processes errors. Optional<pre class="screen" id="EN-US_TOPIC_0000001233761687__sdacce2b6f4734d26ac37ad6b77bd8991">EXCEPTION</pre>
</li><li id="EN-US_TOPIC_0000001233761687__lab3b3baea0f8480793f1311a115113c2"><strong id="EN-US_TOPIC_0000001233761687__b842352706115929">END</strong><pre class="screen" id="EN-US_TOPIC_0000001233761687__se1215a7630664713a0709a9bbc12cd0a">END;
/</pre>
<div class="notice" id="EN-US_TOPIC_0000001233761687__nd58559d6b0e8487881d35fc43f6629fa"><span class="noticetitle"><img src="public_sys-resources/notice_3.0-en-us.png"> </span><div class="noticebody"><p id="EN-US_TOPIC_0000001233761687__a967bc44073a74b13b18bc7c564dd149b">You are not allowed to use consecutive tabs in the PL/SQL block, because they may result in an exception when the parameter <strong id="EN-US_TOPIC_0000001233761687__b8167145482619">-r</strong> is executed using the <strong id="EN-US_TOPIC_0000001233761687__b716865492619">gsql</strong> tool.</p>
</div></div>
</li></ul>
</div>
<div class="section" id="EN-US_TOPIC_0000001233761687__s483fd7e0e07742ca8befe5d3ce2a660f"><h4 class="sectiontitle">Type</h4><p id="EN-US_TOPIC_0000001233761687__a73ec285a716149d586752079572297f1">PL/SQL blocks are classified into the following types:</p>
<ul id="EN-US_TOPIC_0000001233761687__u091dcfac86844c32aa23c187b9115b76"><li id="EN-US_TOPIC_0000001233761687__lb07395f09693447889e7d1ad77a8412a">Anonymous block: a dynamic block that can be executed only for once. For details about the syntax, see <a href="dws_04_0521.html#EN-US_TOPIC_0000001233681699__f0d3f58494e2241b8867d81e8cc747d36">Figure 1</a>.</li><li id="EN-US_TOPIC_0000001233761687__l314411685d8243cfab32d5e8180126e5">Subprogram: a stored procedure, function, operator, or packages stored in a database. A subprogram created in a database can be called by other programs.</li></ul>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_04_0519.html">Syntax</a></div>
</div>
</div>