ibm-information-center/dist/eclipse/plugins/i5OS.ic.sqlp_5.4.0.1/rbafycolum.htm

81 lines
5.2 KiB
HTML

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html lang="en-us" xml:lang="en-us">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="security" content="public" />
<meta name="Robots" content="index,follow" />
<meta http-equiv="PICS-Label" content='(PICS-1.1 "http://www.icra.org/ratingsv02.html" l gen true r (cz 1 lz 1 nz 1 oz 1 vz 1) "http://www.rsac.org/ratingsv01.html" l gen true r (n 0 s 0 v 0 l 0) "http://www.classify.org/safesurf/" l gen true r (SS~~000 1))' />
<meta name="DC.Type" content="reference" />
<meta name="DC.Title" content="Static SELECT statements" />
<meta name="abstract" content="For a static SELECT statement (one embedded in an SQL program), an INTO clause must be specified before the FROM clause." />
<meta name="description" content="For a static SELECT statement (one embedded in an SQL program), an INTO clause must be specified before the FROM clause." />
<meta name="DC.subject" content="SELECT INTO statement, DECLARE CURSOR statement, using, statements, DECLARE CURSOR" />
<meta name="keywords" content="SELECT INTO statement, DECLARE CURSOR statement, using, statements, DECLARE CURSOR" />
<meta name="DC.Relation" scheme="URI" content="rbafytexas.htm" />
<meta name="DC.Relation" scheme="URI" content="rbafycurs.htm" />
<meta name="copyright" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Rights.Owner" content="(C) Copyright IBM Corporation 1998, 2006" />
<meta name="DC.Format" content="XHTML" />
<meta name="DC.Identifier" content="rbafycolum" />
<meta name="DC.Language" content="en-us" />
<!-- All rights reserved. Licensed Materials Property of IBM -->
<!-- US Government Users Restricted Rights -->
<!-- Use, duplication or disclosure restricted by -->
<!-- GSA ADP Schedule Contract with IBM Corp. -->
<link rel="stylesheet" type="text/css" href="./ibmdita.css" />
<link rel="stylesheet" type="text/css" href="./ic.css" />
<title>Static SELECT statements</title>
</head>
<body id="rbafycolum"><a name="rbafycolum"><!-- --></a>
<!-- Java sync-link --><script language="Javascript" src="../rzahg/synch.js" type="text/javascript"></script>
<h1 class="topictitle1">Static SELECT statements</h1>
<div><p>For a static SELECT statement (one embedded in an SQL program),
an INTO clause must be specified before the FROM clause.</p>
<div class="section"><p>The INTO clause names the host variables (variables in your program
used to contain retrieved column values). The value of the first result column
specified in the SELECT clause is put into the first host variable named in
the INTO clause; the second value is put into the second host variable, and
so on.</p>
</div>
<div class="section"><p>The result table for a SELECT INTO should contain just one row.
For example, each row in the CORPDATA.EMPLOYEE table has a unique EMPNO (employee
number) column. The result of a SELECT INTO statement for this table if the
WHERE clause contains an equal comparison on the EMPNO column, will be exactly
one row (or no rows). Finding more than one row is an error, but one row is
still returned. You can control which row will be returned in this error condition
by specifying the ORDER BY clause. If you use the ORDER BY clause, the first
row in the result table is returned.</p>
</div>
<div class="section"><p>If you want more than one row to be the result of a SELECT INTO
statement, use a DECLARE CURSOR statement to select the rows, followed by
a FETCH statement to move the column values into host variables one or many
rows at a time. </p>
</div>
<div class="section"><p>When using the select-statement in an application program, list
the column names to give your program more data independence. There are two
reasons for this: </p>
</div>
<div class="section"> <ol><li>When you look at the source code statement, you can easily see the one-to-one
correspondence between the column names in the SELECT clause and the host
variables named in the INTO clause.</li>
<li>If a column is added to a table or view you access and you use <span class="q">"SELECT
* ...,"</span> and you create the program again from source, the INTO clause does
not have a matching host variable named for the new column. The extra column
causes you to get a warning (not an error) in the SQLCA (SQLWARN3 will contain
a <span class="q">"W"</span>). When using the GET DIAGNOSTICS statement, the RETURNED_SQLSTATE
item will have a value of '01503'.</li>
</ol>
</div>
</div>
<div>
<div class="familylinks">
<div class="parentlink"><strong>Parent topic:</strong> <a href="rbafytexas.htm" title="Learn a variety of ways of tailoring your query to gather data using the SELECT statement. One way to do this is to use the SELECT statement in a program to retrieve a specific row (for example, the row for an employee). Furthermore, you can use clauses to gather data in a specific way.">Retrieve data using the SELECT statement</a></div>
</div>
<div class="relref"><strong>Related reference</strong><br />
<div><a href="rbafycurs.htm" title="When SQL runs a select statement, the resulting rows comprise the result table. A cursor provides a way to access a result table.">Use a cursor</a></div>
</div>
</div>
</body>
</html>