forked from docs/doc-exports
Reviewed-by: Pruthi, Vineet <vineet.pruthi@t-systems.com> Co-authored-by: luhuayi <luhuayi@huawei.com> Co-committed-by: luhuayi <luhuayi@huawei.com>
191 lines
17 KiB
HTML
191 lines
17 KiB
HTML
<a name="EN-US_TOPIC_0000001813598536"></a><a name="EN-US_TOPIC_0000001813598536"></a>
|
|
|
|
<h1 class="topictitle1">BTEQ Utility Command</h1>
|
|
<div id="body8662426"><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p164443717352">GaussDB(DWS) provides gsql meta-commands that can be used to replace common BTEQ tool commands. The mostly used replacements are as follows:</p>
|
|
<div class="section" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_section57838262517"><h4 class="sectiontitle">.QUIT | .EXIT | .RETURN</h4><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p016381116423">The meta-command <strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b545116319427">\q [</strong><em id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_i1297411594419">value</em><strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b15451113154214">]</strong> can be used to exit the gsql program, and <strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b7346103934215">value</strong> specifies the exit code. The .QUIT, .EXIT, and .RETURN commands can replace each other with the <strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b11602185315441">\q</strong> command.</p>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_table1579232718401" frame="border" border="1" rules="all"><thead align="left"><tr id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_row16792112717409"><th align="left" class="cellrowborder" valign="top" width="50%" id="mcps1.3.2.3.1.3.1.1"><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p18792152716401"><strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b3808164143312">Input</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="50%" id="mcps1.3.2.3.1.3.1.2"><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p1879202710409"><strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b48833669731949">Output</strong></p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_row177921727164011"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.2.3.1.3.1.1 "><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p1361194791018">.QUIT 0</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.2.3.1.3.1.2 "><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p1879262754015">\q 0</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_row279252754012"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.2.3.1.3.1.1 "><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p6792142714406">.EXIT</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.2.3.1.3.1.2 "><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p127924272406">\q</p>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_row07921527164011"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.2.3.1.3.1.1 "><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p679262794012">.RETURN</p>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.2.3.1.3.1.2 "><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p19792172774011">\q</p>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_section12154105915298"><h4 class="sectiontitle">.LABEL and .GOTO</h4><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p46501248113620">The Teradata command .LABEL is used to create tags and is usually used together with .GOTO. .GOTO skips all intermediate BTEQ commands and SQL statements, instructs you to reach the specified label position, and performs corresponding restoration processing.</p>
|
|
<p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p5892087162">gsql meta-command <strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b1477671815104">\goto LABEL...</strong> and <strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b134811438141015">\label LABEL</strong> can be replaced with each other with no constraints.</p>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_table595124913416" frame="border" border="1" rules="all"><thead align="left"><tr id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_row199511849124111"><th align="left" class="cellrowborder" valign="top" width="50%" id="mcps1.3.3.4.1.3.1.1"><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p69511249114110"><strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b1589410321913">Input</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="50%" id="mcps1.3.3.4.1.3.1.2"><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p19511049144116"><strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b132669177031949">Output</strong></p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_row1895110499410"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.4.1.3.1.1 "><pre class="screen" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_screen9673193923219">.IF CHECK_PK='' THEN .GOTO NOCHECK
|
|
${CHECK_PK};
|
|
.LABEL NOCHECK
|
|
.QUIT 0</pre>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.3.4.1.3.1.2 "><pre class="screen" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_screen116974315321">\if ${CHECK_PK} == ''
|
|
\goto NOCHECK
|
|
\endif
|
|
${CHECK_PK}
|
|
\label NOCHECK
|
|
\q 0</pre>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_section62913118302"><h4 class="sectiontitle">.RUN FILE</h4><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p131047484119">Executing the SQL request of a specified file can be implemented by the gsql meta-command <strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b1463782015113">\i</strong>.</p>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_table13511145213455" frame="border" border="1" rules="all"><thead align="left"><tr id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_row7511135264520"><th align="left" class="cellrowborder" valign="top" width="50%" id="mcps1.3.4.3.1.3.1.1"><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p851110527456"><strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b16257184391111">Input</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="50%" id="mcps1.3.4.3.1.3.1.2"><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p35111252104520"><strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b16647408431949">Output</strong></p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_row55111526450"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.4.3.1.3.1.1 "><pre class="screen" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_screen135587305322">.RUN FILE=sampfile</pre>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.4.3.1.3.1.2 "><pre class="screen" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_screen596073323213">\i 'sampfile'</pre>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_section1198119153015"><h4 class="sectiontitle">.EXPORT FILE</h4><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p588681824715">Exporting the SQL statement execution result to a specified file can be implemented by the gsql meta-command <strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b1331379101217">\o</strong>.</p>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_table1682761411471" frame="border" border="1" rules="all"><thead align="left"><tr id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_row48287147472"><th align="left" class="cellrowborder" valign="top" width="50%" id="mcps1.3.5.3.1.3.1.1"><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p1582812141472"><strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b1374591331214">Input</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="50%" id="mcps1.3.5.3.1.3.1.2"><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p1182810148475"><strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b140468203531949">Output</strong></p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_row1282871434716"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.5.3.1.3.1.1 "><pre class="screen" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_screen1748962253215">.EXPORT REPORT FILE=resultfile</pre>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.5.3.1.3.1.2 "><pre class="screen" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_screen15263102673216">\o 'resultfile'</pre>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_section1371511217304"><h4 class="sectiontitle">..SET ..END</h4><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p20868105373219">To set a variable to specified value, both a single-line command or a multi-line command ended with ..END can be used. You can run the SELECT command to query a specified variable name or run the <strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b1065683142216">\set</strong> command to convert the variable name.</p>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_table5369547439" frame="border" border="1" rules="all"><thead align="left"><tr id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_row23691847438"><th align="left" class="cellrowborder" valign="top" width="50%" id="mcps1.3.6.3.1.3.1.1"><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p736954716314"><strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b4318954171215">Input</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="50%" id="mcps1.3.6.3.1.3.1.2"><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p936913472317"><strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b133540618531949">Output</strong></p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_row123698471531"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.6.3.1.3.1.1 "><pre class="screen" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_screen55811714143213">.SET SEPARATOR ' | '</pre>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.6.3.1.3.1.2 "><pre class="screen" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_screen176075181326">\set SEPARATOR '|'</pre>
|
|
</td>
|
|
</tr>
|
|
<tr id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_row1636912471839"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.6.3.1.3.1.1 "><pre class="screen" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_screen567114673219">..SET NAME
|
|
'Jack'
|
|
..END</pre>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.6.3.1.3.1.2 "><pre class="screen" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_screen359813108328">SELECT 'Jack' AS "NAME";</pre>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_section1464832213518"><h4 class="sectiontitle">.IF</h4><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p5917104517715">.IF is one of the important process control commands used to execute parts of an input script. It can be a single-branch command, which is used in pairs with the THEN clause. It can also be a multi-branch command. The multi-branch IF structure allows multiple nested layers, but each layer must start with the IF command and end with the ENDIF command.</p>
|
|
<p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p1880192911010">The flow control meta-commands <strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b198641829192710">\if...</strong> \else ... <strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b036813341278">\endif</strong> can be used to replace this BTEQ command.</p>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_table3542229101110" frame="border" border="1" rules="all"><thead align="left"><tr id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_row35432029121116"><th align="left" class="cellrowborder" valign="top" width="50%" id="mcps1.3.7.4.1.3.1.1"><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p55431290115"><strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b128671315102913">Input</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="50%" id="mcps1.3.7.4.1.3.1.2"><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p205433296117"><strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b86193570631949">Output</strong></p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_row14543162913110"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.7.4.1.3.1.1 "><pre class="screen" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_screen192925588317">.IF ERRORCODE <> 0 THEN .QUIT 12;</pre>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.7.4.1.3.1.2 "><pre class="screen" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_screen242312113216">\if ${ERROR} != 'false'
|
|
\q 12
|
|
\endif</pre>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
<div class="section" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_section42025374315"><h4 class="sectiontitle">..FOR</h4><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p192871744944">In the loop control command, when the loop condition is met, the script of the loop body can be executed continuously until .QUIT exits the loop. GaussDB(DWS) provides<strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b129349519577"> \for...</strong> \loop ... \exit-for ... <strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b13189121445715">\end-for</strong> structure command implements the loop logic.</p>
|
|
|
|
<div class="tablenoborder"><table cellpadding="4" cellspacing="0" summary="" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_table184882317507" frame="border" border="1" rules="all"><thead align="left"><tr id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_row1349122312506"><th align="left" class="cellrowborder" valign="top" width="50%" id="mcps1.3.8.3.1.3.1.1"><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p194913234503"><strong id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_b9594103034912">Input</strong></p>
|
|
</th>
|
|
<th align="left" class="cellrowborder" valign="top" width="50%" id="mcps1.3.8.3.1.3.1.2"><p id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_p1249152375018">Output</p>
|
|
</th>
|
|
</tr>
|
|
</thead>
|
|
<tbody><tr id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_row1249162311508"><td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.8.3.1.3.1.1 "><pre class="screen" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_screen133991449312">..IF ACTIVITYCOUNT > 0 THEN
|
|
..FOR
|
|
SEL SqlStr AS V_SqlStr
|
|
FROM ${ ETL_DATA}.TB_DWDATA_UPDATE
|
|
WHERE JobName = '${JOB_NAME}'
|
|
AND TXDATE = ${ TX_DATE} - 19000000
|
|
ORDER BY ExcuteSeq ASC;
|
|
..DO
|
|
${V_SqlStr}
|
|
.IF ERRORCODE<>0 THEN .QUIT 12
|
|
..END-FOR
|
|
..END-IF</pre>
|
|
</td>
|
|
<td class="cellrowborder" valign="top" width="50%" headers="mcps1.3.8.3.1.3.1.2 "><pre class="screen" id="EN-US_TOPIC_0000001813598536__en-us_topic_0000001449515369_screen104041452183118">\if ${ERROR} != 'false'
|
|
\q 12
|
|
\endif
|
|
\if ${ACTIVITYCOUNT} != 0
|
|
\for
|
|
SELECT
|
|
SqlStr AS V_SqlStr
|
|
FROM
|
|
${ETL_DATA}.TB_DWDATA_UPDATE
|
|
WHERE
|
|
JobName = '${JOB_NAME}'
|
|
AND TXDATE = to_date( ${TX_DATE} ,'yyyymmdd' )
|
|
ORDER BY
|
|
ExcuteSeq ASC
|
|
\loop
|
|
${V_SqlStr} ;
|
|
\if ${ERROR} != 'false'
|
|
\q 12
|
|
\endif
|
|
\end-for
|
|
\endif</pre>
|
|
</td>
|
|
</tr>
|
|
</tbody>
|
|
</table>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div>
|
|
<div class="familylinks">
|
|
<div class="parentlink"><strong>Parent topic:</strong> <a href="dws_16_0036.html">Teradata Syntax Migration</a></div>
|
|
</div>
|
|
</div>
|
|
|