Sophie

Sophie

distrib > Fedora > 14 > x86_64 > media > updates > by-pkgid > 71d40963b505df4524269198e237b3e3 > files > 39

virtuoso-opensource-doc-6.1.4-2.fc14.noarch.rpm

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
 <head profile="http://internetalchemy.org/2003/02/profile">
  <link rel="foaf" type="application/rdf+xml" title="FOAF" href="http://www.openlinksw.com/dataspace/uda/about.rdf" />
  <link rel="schema.dc" href="http://purl.org/dc/elements/1.1/" />
  <meta name="dc.title" content="9. SQL Procedure Language Guide" />
  <meta name="dc.subject" content="9. SQL Procedure Language Guide" />
  <meta name="dc.creator" content="OpenLink Software Documentation Team ;&#10;" />
  <meta name="dc.copyright" content="OpenLink Software, 1999 - 2009" />
  <link rel="top" href="index.html" title="OpenLink Virtuoso Universal Server: Documentation" />
  <link rel="search" href="/doc/adv_search.vspx" title="Search OpenLink Virtuoso Universal Server: Documentation" />
  <link rel="parent" href="sqlprocedures.html" title="Chapter Contents" />
  <link rel="prev" href="EXCEPTIONS.html" title="Exception Semantics" />
  <link rel="next" href="EXECSQLPROCSELECT.html" title="Execute Stored Procedures via SELECT statement" />
  <link rel="shortcut icon" href="../images/misc/favicon.ico" type="image/x-icon" />
  <link rel="stylesheet" type="text/css" href="doc.css" />
  <link rel="stylesheet" type="text/css" href="/doc/translation.css" />
  <title>9. SQL Procedure Language Guide</title>
  <meta http-equiv="Content-Type" content="text/xhtml; charset=UTF-8" />
  <meta name="author" content="OpenLink Software Documentation Team ;&#10;" />
  <meta name="copyright" content="OpenLink Software, 1999 - 2009" />
  <meta name="keywords" content="" />
  <meta name="GENERATOR" content="OpenLink XSLT Team" />
 </head>
 <body>
  <div id="header">
    <a name="PLREF" />
    <img src="../images/misc/logo.jpg" alt="" />
    <h1>9. SQL Procedure Language Guide</h1>
  </div>
  <div id="navbartop">
   <div>
      <a class="link" href="sqlprocedures.html">Chapter Contents</a> | <a class="link" href="EXCEPTIONS.html" title="Exception Semantics">Prev</a> | <a class="link" href="EXECSQLPROCSELECT.html" title="Execute Stored Procedures via SELECT statement">Next</a>
   </div>
  </div>
  <div id="currenttoc">
   <form method="post" action="/doc/adv_search.vspx">
    <div class="search">Keyword Search: <br />
        <input type="text" name="q" /> <input type="submit" name="go" value="Go" />
    </div>
   </form>
   <div>
      <a href="http://www.openlinksw.com/">www.openlinksw.com</a>
   </div>
   <div>
      <a href="http://docs.openlinksw.com/">docs.openlinksw.com</a>
   </div>
    <br />
   <div>
      <a href="index.html">Book Home</a>
   </div>
    <br />
   <div>
      <a href="contents.html">Contents</a>
   </div>
   <div>
      <a href="preface.html">Preface</a>
   </div>
    <br />
   <div class="selected">
      <a href="sqlprocedures.html">SQL Procedure Language Guide</a>
   </div>
    <br />
   <div>
      <a href="GENERALPRINCIPLES.html">General Principles</a>
   </div>
   <div>
      <a href="SCOPEOFDECLARATION.html">Scope of Declarations</a>
   </div>
   <div>
      <a href="sqlplDATATYPES.html">Data Types</a>
   </div>
   <div>
      <a href="RESULTSETS.html">Handling Result Sets</a>
   </div>
   <div>
      <a href="ARRAYS.html">Result Sets and Array Parameters</a>
   </div>
   <div>
      <a href="EXCEPTIONS.html">Exception Semantics</a>
   </div>
   <div class="selected">
      <a href="PLREF.html">Virtuoso/PL Syntax</a>
    <div>
        <a href="#createprocstmt" title="Create Procedure Statement">Create Procedure Statement</a>
        <a href="#grantprocstmt" title="Grand Execute Statement">Grand Execute Statement</a>
        <a href="#spasviewsandtablespl" title="Stored Procedures as Views &amp; Derived Tables">Stored Procedures as Views &amp; Derived Tables</a>
        <a href="#kwds" title="Keyword and Optional Procedure Arguments">Keyword and Optional Procedure Arguments</a>
        <a href="#whilestmt" title="if, while, for, foreach statements">if, while, for, foreach statements</a>
        <a href="#compoundstmts" title="compound statement">compound statement</a>
        <a href="#gotortnstmts" title="goto, return statements">goto, return statements</a>
        <a href="#wheneverstmt" title="whenever statement">whenever statement</a>
        <a href="#callassignstmt" title="call, assignment statements">call, assignment statements</a>
        <a href="#openfetchetcintostmts" title="open, fetch, close, select ... into statements">open, fetch, close, select ... into statements</a>
        <a href="#forstmt" title="FOR Select Statement">FOR Select Statement</a>
        <a href="#setstmt" title="SET statement">SET statement</a>
        <a href="#settriggers" title="SET Triggers">SET Triggers</a>
    </div>
   </div>
   <div>
      <a href="EXECSQLPROCSELECT.html">Execute Stored Procedures via SELECT statement</a>
   </div>
   <div>
      <a href="EXECSQLPROCFORK.html">Execute Stored Procedures In Background</a>
   </div>
   <div>
      <a href="createassembly.html">CREATE ASSEMBLY Syntax - External Libraries</a>
   </div>
   <div>
      <a href="createexthostproc.html">CREATE PROCEDURE Syntax - External hosted procedures</a>
   </div>
   <div>
      <a href="ASYNCEXECMULTITHREAD.html">Asynchronous Execution and Multithreading in Virtuoso/PL</a>
   </div>
   <div>
      <a href="PERFTIPS.html">Performance Tips</a>
   </div>
   <div>
      <a href="PROCEDURES_TRANSACTIONS.html">Procedures and Transactions</a>
   </div>
   <div>
      <a href="twopcimplementation.html">Distributed Transaction &amp; Two Phase Commit</a>
   </div>
   <div>
      <a href="TRIGGERS.html">Triggers</a>
   </div>
   <div>
      <a href="charescaping.html">Character Escaping</a>
   </div>
   <div>
      <a href="PLSCROLLCRSRS.html">Virtuoso/PL Scrollable Cursors</a>
   </div>
   <div>
      <a href="plmodules.html">Virtuoso PL Modules</a>
   </div>
   <div>
      <a href="handlingplcondit.html">Handling Conditions In Virtuoso/PL Procedures</a>
   </div>
   <div>
      <a href="pldebugger.html">Procedure Language Debugger</a>
   </div>
   <div>
      <a href="rowlevelsecurity.html">Row Level Security</a>
   </div>
    <br />
  </div>
  <div id="text">
		<a name="PLREF" />
    <h2>9.7. Virtuoso/PL Syntax</h2>
		
		
			<a name="createprocstmt" />
    <h3>9.7.1. Create Procedure Statement</h3>
			<div>
      <pre class="programlisting">
CREATE PROCEDURE NAME (parameter , parameter...) [RETURNS data_type]
{ statement ... }

parameter: parameter_type name data_type opt_default

parameter_type: IN | OUT | INOUT

opt_default: | DEFAULT literal | := literal
</pre>
    </div>
  <p>The create procedure statement actually performs a &quot;create or
  replace&quot; type operation.  The create procedure statement compiles and stores a
  Virtuoso/PL procedure. The procedure text is first parsed and compiled into
  Virtuoso virtual machine code and if the compilation is successful the text
  is stored into the SYS_PROCEDURES table. This table is read at startup.
  Stored procedures are thus always available for use and need be defined
  only once.  New procedures created with the same name as existing procedures
  automatically replace their predecessor.</p>
  <div class="tip">
      <div class="tiptitle">See Also:</div>
      <p>
        <a href="createexthostproc.html">CREATE PROCEDURE Syntax - External hosted procedures</a>
      </p>
    </div>
			<div>
      <pre class="screen">
CREATE PROCEDURE FIBO (IN X INTEGER)
{
    IF (X &lt; 2)
	RETURN X;
    ELSE
	RETURN (FIBO (X - 1) + FIBO (X - 2));
}

CREATE PROCEDURE CFIBO (IN X INTEGER)
{
    DECLARE RES INTEGER;

    RES := FIBO (X);

    RESULT_NAMES (RES);

    RESULT (RES);
}
</pre>
    </div>
<br />
		
			<a name="grantprocstmt" />
    <h3>9.7.2. Grand Execute Statement</h3>
<div>
      <pre class="programlisting">
GRANT EXECUTE ON proceudre_name TO grantee_commalist;
</pre>
    </div>
<p>The grantee should have SQL rights in order execution of procedure to be granted to this user.
The rights can be set from Conductor-&gt;System Admin-&gt;User Accounts-&gt;Account-&gt;Edit-&gt;User Type:</p>
     <table class="figure" border="0" cellpadding="0" cellspacing="0">
    <tr>
     <td>
          <img alt="User Type" src="../images/ui/usrt.png" />
     </td>
    </tr>
    <tr>
        <td>Figure: 9.7.2.1. User Type</td>
    </tr>
    </table>
<p>
      <strong>Example</strong>
    </p>
<div>
      <pre class="programlisting">
SQL&gt;create procedure DB.DBA.SimplePrint (in txt varchar)
{
 return sprintf(&#39;Output is %s&#39;, txt);
}
;

Done. -- 0 msec.

SQL&gt;grant execute on DB.DBA.SimplePrint to &quot;demo&quot;;

Done. -- 0 msec.

SQL&gt;use demo;

Done. -- 0 msec.

SQL&gt;select DB.DBA.SimplePrint(&#39;Virtuoso&#39;);

callret
VARCHAR
_______________________________________________________________________________

Output is Virtuoso

1 Rows. -- 0 msec.

</pre>
    </div>
<br />
	
		<a name="spasviewsandtablespl" />
    <h3>9.7.3. Stored Procedures as Views &amp; Derived Tables</h3>
		<p>
Virtuoso allows using a stored procedure result set in place of a table. A view may also be
defined as a stored procedure. This provides smooth integration to external
procedural logic in queries.
</p>
		<p>
When a procedure appears as a table, the procedure is called and its result set is inserted
into a temporary space. Processing continues from that point on as if the data came from a table.
</p>

<div class="tip">
      <div class="tiptitle">See Also:</div>
<p>For more information about Store Procedures as Views &amp; Derived Tables go to the
<a href="spasviewsandtables.html">SQL Reference Chapter</a>
      </p>
    </div>
		<br />

		
			<a name="kwds" />
    <h3>9.7.4. Keyword and Optional Procedure Arguments</h3>
<p>
Normally arguments in a procedure call are bound to formal parameters from left to right, as is
the default behavior in any programming language.  If a default value is specified for a parameter
in the procedure definition this parameter is optional and the default value will
be assigned to it if the caller does not specify a value.
A call may consist of zero or more positional arguments followed by zero or more keyword
arguments.  A positional argument is any scalar expression.
A keyword argument is marked with the syntax:
</p>
<div>
      <pre class="programlisting">
NAME =&gt; scalar_exp
</pre>
    </div>
<p>
This notation specifies that the expression is to be bound to the parameter NAME in the
procedure declaration.  The names are matched case-insensitively in all case modes.
After all leading positional arguments have been bound to the matching formal parameters
in the procedure definition, each keyword argument is bound to the parameter of the same name.
After this all unbound formal parameters are assigned to their default values.
If a parameter with no default remains unbound an error is signalled.  OUT and INOUT
parameters are always required, regardless of the mode of calling.
</p>
<p>
An expression can be passed as INOUT or OUT, but in that case the output
value assigned by the procedure is not accessible in the caller.  The output value
is only accessible if the actual parameter is a variable or parameter.
</p>
<p>
Arguments of procedures are always evaluated left to right.
</p>

<div>
      <pre class="programlisting">
create procedure kwd (in k1 int := 111, inout k2 int, in k3 int := 333)
{
  result_names (k1, k2, k3);
  result (k1, k2, k3);
}

kwd (1,1+1,3);
-- results 1,2,3

kwd ();
-- error because inout parameters are always required

kwd (k2=&gt;1);
-- error because a constant is not a suitable value for an inout parameter.

kwd (k2=&gt;1+2);
-- result 111, 2, 333

kwd (k3=&gt;3, k1=&gt;1,k2=&gt;1+1);
-- result 1, 2, 3

kwd (1, k2=&gt;1+1);
-- result 1, 2, 333
kwd (1);
-- error, k2 is required
kwd (badkey=&gt;2, k2=&gt;2+1);
-- error, badkey not a parameter of the function

create procedure kwd2 (in k1 int , in k2 int, in k3 int)
{
  result_names (k1, k2, k3);
  result (k1, k2, k3);
}

kwd2 (k1=&gt;1, k2=&gt;2, k3=&gt;3);
-- result 1, 2, 3
kwd2 (1,2,3);
-- result 1, 2, 3
</pre>
    </div>
<br />

		
		
			<a name="whilestmt" />
    <h3>9.7.5. if, while, for, foreach statements</h3>
			<div>
      <pre class="programlisting">
if_statement
	: IF &#39;(&#39; search_condition &#39;)&#39; statement opt_else

opt_else
	: /* empty */
	| ELSE statement

while_statement
	: WHILE &#39;(&#39; search_condition &#39;)&#39; statement

for_statement
  :	FOR &#39;(&#39; for_init_statement_list &#39;;&#39; for_opt_search_cond &#39;;&#39; for_inc_statement_list &#39;)&#39; statement
  | FOREACH &#39;(&#39; data_type_ref identifier IN_L scalar_exp &#39;)&#39; DO statement
</pre>
    </div>
			<p>
The IF statement executes the immediately following statement if the
condition is true. If there is an else clause and the condition is false
the statement immediately following the else keyword will be executed.
</p>
			<p>
The while statement evaluates the search condition and executes the
following statement if the condition is true. It does this as long as
the condition is true. To exit from a loop, use goto. C-like break and
continue statements are not available.
</p>
			<p>
The for statement initiates the for_init_statement_list and executes
the following statement until the search condition is true. After
every execution of the statement it executes for_inc_statement_list.
You can exit the loop with using goto syntax also.
</p>
			<p>
The foreach statement executes the statement for each element from
an array and sets a variable to the corresponding element of that array.
</p>
			<div>
      <pre class="screen">
IF (A &gt; B)
    A := A + 1;
ELSE
    B := B + 1;

WHILE (1 = 1) {
    A := A + 1;
}

FOR (declare X any, X := 1; X &lt;= 2 ; X := X + 1){
    S := S + X;
}

FOR (declare X any, X := 1; X &lt;= 2 ; ){
    S := S + X;
    X := X + 1;
}

FOR (declare X any, X := 1; ; X := X + 1){
    if (X &gt; 2)
    goto exit_loop;
    S := S + X;
}
exit_loop:

declare X integer;
X := 1;
FOR (; X &lt;= 2 ; X := X + 1){
    S := S + X;
}

ARR := vector (1,2);
FOREACH (int X in ARR) do {
    S := S + X;
}
</pre>
    </div>
		<br />
		
		
			<a name="compoundstmts" />
    <h3>9.7.6. compound statement</h3>
			<div>
      <pre class="programlisting">
compound_statement
	: &#39;{&#39; statement_list &#39;}&#39;
	;

statement_list
   	: statement_in_cs
	| statement_list statement_in_cs
	;

statement_in_cs
	: local_declaration &#39;;&#39;
	| compound_statement
	| routine_statement &#39;;&#39;
	| control_statement
	| label &#39;:&#39; statement
	;

statement
	: routine_statement &#39;;&#39;
	| control_statement
	| compound_statement
	;

local_declaration
	: cursor_def
	| variable_declaration
	| handler_declaration
	;

variable_declaration
	: DECLARE variable_list data_type
	;


variable_list
	: NAME
	| variable_list &#39;,&#39; NAME
	;
</pre>
    </div>
			<p>The compound statement is the main building block of
procedures. Statements in a compound statement are executed left to right,
unless the flow of control is changed with a goto statement. The compound
statement allows declaring local variables and exception handlers.
See &#39;Scope Rules&#39; above for a description of the scope of declarations.
</p>
			<p>
Labeled statements (goto targets) and declarations can only occur within
a compound statement.
</p>
			<div class="tip">
				<div class="tiptitle">See:</div>
				<p>
        <a href="PLREF.html#createprocstmt">Create Procedure statement</a>
      </p>
			</div>
		<br />
		
		
			<a name="gotortnstmts" />
    <h3>9.7.7. goto, return statements</h3>
			<div>
      <pre class="programlisting">
goto_statement
	: GOTO label
	;

label	: NAME

return_statement
	: RETURN scalar_exp
	| RETURN
	;
</pre>
    </div>
			<p>The goto statement unconditionally transfers control to the label
following it. The label can be anywhere within the same procedure. It is
in principle possible to jump into a block (e.g. loop body) from outside.
</p>
			<p>
The return statement causes the executing procedure to return. If a
return value is specified the expression is evaluated and returned as
the return value of the procedure. If no return value is specified the
procedure returns an undefined value.
</p>
			<p>
Returning from a procedure automatically frees any resources associated
with the procedure. This includes values in local variables or call by
value (IN) parameters and any cursors that may be open.
</p>
			<div class="tip">
				<div class="tiptitle">See:</div>
				<p>
        <a href="PLREF.html#createprocstmt">Create Procedure statement</a>
      </p>
			</div>
		<br />
		
		
			<a name="wheneverstmt" />
    <h3>9.7.8. whenever statement</h3>
			<div>
      <pre class="programlisting">
condition
	: NOT FOUND
	| SQLSTATE STRING
	;

handler_declaration
	: WHENEVER condition GOTO NAME
	;
</pre>
    </div>
			<p>This declares that control should be transferred to a particular label
in the procedure whenever a condition occurs within the lexical scope
of the WHENEVER declaration. This is similar to the statement of the
same name found in most embedded SQL implementations.
</p>
			<p>
The scope of the declaration is all the lines lexically following the
declaration. A previous declaration is replaced by a new declaration
for the same &lt;condition&gt;.
</p>
			<div>
      <pre class="screen">
CREATE PROCEDURE COUNT_CUSTOMERS (IN C_NAME VARCHAR)
{
    DECLARE COUNT INTEGER;

    COUNT := 0;

    DECLARE C CURSOR FOR SELECT C_ID FROM CUSTOMER WHERE C_NAME = C_NAME;

    WHENEVER SQLSTATE &#39;4001&#39; GOTO DEADLOCK;

    WHENEVER NOT FOUND GOTO DONE;

    OPEN C;
    WHILE (1=1)
    {
	FETCH C INTO N;
	COUNT := COUNT + 1;
    }

DONE:
    RETURN COUNT;

DEADLOCK:
    RETURN -1;
}
</pre>
    </div>
			<div class="note">
				<div class="notetitle">Note:</div>
				<p>This is about the same as select count (*) from CUSTOMER where C_NAME = ?; </p>
			</div>
		<br />
		
		
			<a name="callassignstmt" />
    <h3>9.7.9. call, assignment statements</h3>
			<div>
      <pre class="programlisting">
function_call
	: NAME &#39;(&#39; opt_scalar_exp_commalist &#39;)&#39;
	| call &#39;(&#39; scalar_exp &#39;)&#39; &#39;(&#39;opt_scalar_exp_commalist &#39;)&#39;
	;

call_statement
	: CALL NAME &#39;(&#39; opt_scalar_exp_commalist &#39;)&#39;
	| function_call
	;

assignment_statement
	: lvalue EQUALS scalar_exp
	| lvalue &#39;=&#39; scalar_exp
	;

lvalue	:  NAME
</pre>
    </div>
			<p>The call statement calls a specified procedure with the given arguments.
The procedure to call is resolved at run time, i.e. the latest definition
prevails, even if it has been made after the calling procedure was
defined. The CALL reserved word is optional and is supported for
compatibility.
</p>
			<p>
If the called procedure has reference parameters (OUT or INOUT) the
matching actual parameter must be a variable or parameter.
</p>
			<p>
There is a computed function call form of function_call. In this,
the scalar expression in parentheses following the call keyword should
evaluate to a string which then identifies the function to be called.
</p>
			<p>
The assignment statement sets a value to a variable. The variable must
be either a local variable declared with declare or a procedure argument
declared in the procedure argument list. If the variable in question is
a reference parameter the assignment takes effect in the actual parameter
as will, i.e. the value of the argument variable in the caller is set.
</p>
			<div>
      <pre class="screen">
CREATE PROCEDURE COMPUTED_CALL (IN Q INTEGER)
{
    DECLARE FN VARCHAR;

    FN := &#39;F&#39;;

    --- CALL FUNCTION FF WITH ARGUMENT 11.
    R := CALL (CONCATENATE (FN, &#39;F&#39;)) (11);
}
</pre>
    </div>
		<br />
		
		
			<a name="openfetchetcintostmts" />
    <h3>9.7.10. open, fetch, close, select ... into statements</h3>
			<div>
      <pre class="programlisting">
SELECT opt_all_distinct selection
    INTO target_commalist
    table_exp
    with_opt_cursor_options_list
    ;

opt_all_distinct
	: /* empty */
	| ALL
	| DISTINCT
	;

with_opt_cursor_options_list
	: /* empty */
	| WITH opt_cursor_options_list
	;

cursor_option
	: EXCLUSIVE
	;

cursor_options_commalist
	: cursor_option
	| cursor_options_commalist &#39;,&#39; cursor_option
	;

opt_cursor_options_list
	: /* empty */
	| &#39;(&#39; cursor_options_commalist &#39;)&#39;
	;

cursor_def : DECLARE NAME CURSOR FOR query_exp
           | DECLARE NAME (DYNAMIC|KEYSET|STATIC) CURSOR FOR query_exp

open_statement
	: OPEN cursor opt_cursor_options_list
	;

fetch_statement : FETCH cursor INTO target_commalist
                | FETCH cursor (FIRST|NEXT|PREVIOUS|LAST) INTO target_commalist
                | FETCH cursor BOOKMARK scalar_exp INTO target_commalist

target_commalist
	: variable
	| target_commalist &#39;,&#39; variable
	;

close_statement
	: CLOSE cursor
	;
</pre>
    </div>
			<p>The open, fetch and close statements manipulate cursors in Virtuoso/PL
statements. Cursors are declared with the declare cursor statement.
The select into statement is a shorthand for a cursor declaration, open,
fetch and close.
</p>
			<p>
A forward-only cursor declaration is a declaration only and executing one does not
take time. The open statement effectively starts the search associated
with the forward-only cursor.
</p>
			<p>
The forward-only cursor options used with open and select into allow controlling how
the cursor sets locks on selected rows and how many rows it fetches at
a time.  The EXCLUSIVE option should be
used if intending to update or delete a row in the cursor&#39;s evaluation.
This causes selected rows to be locked with exclusive (write) locks.
</p>
			<div>
      <pre class="screen">
The statements:

{
    DECLARE CR CURSOR FOR SELECT C_NAME FROM CUSTOMER WHERE C_ID = ID;
    OPEN CR;
    FETCH CR INTO NAME;
    CLOSE CR;
}

and

SELECT C_NAME INTO NAME FROM CUSTOMER WHERE C_ID = ID;

have the same effect.
</pre>
    </div>
			<div class="tip">
				<div class="tiptitle">See:</div>
				<p>the <a href="">TPC C Bench Marking</a> chapter for more examples.</p>
			</div>
		<br />
		

		
		
			<a name="forstmt" />
    <h3>9.7.11. FOR Select Statement</h3>
			<div>
      <pre class="programlisting">
&lt;for statement&gt; ::=
     FOR &lt;query exp&gt; DO statement
</pre>
    </div>
			<p>
The FOR statement provides a compact notation for iterating over the result
set of a cursor.  The body is executed once for each row in the query expression&#39;s result set.
The result columns produced by the query expression are accessible as variables of the same
name inside the body.  All result columns do therefore have to be named with the AS declaration
if they are not simple columns, in which case the name defaults to the column&#39;s name.
</p>
			<p>
The body can be exited in mid loop with a goto. The cursor of the FOR does not
have to be specifically closed or opened.  FOR statements can be freely nested.
If a WHENEVER NOT FOUND declaration is in effect before the FOR it will be canceled
by it, so that it is not in effect after the loop&#39;s body.
</p>
			<a name="" />
    <div class="example">
				<div class="exampletitle">Examples</div>
				<div>
        <pre class="programlisting">
for select C_NAME, sum (O_VALUE) as value  from CUSTOMER, ORDER group by C_NAME DO
  {
    result (C_NAME, value);
  })
</pre>
      </div>
				<p>
The equivalent code is
</p>
				<div>
        <pre class="programlisting">
declare C_NAME, value any;
whenever not found goto done;
declare cr cursor for select ....;
open cr;
while (1) {
  fetch cr into C_NAME, value;
  whenever not found default;
  ...
}
done: ;
</pre>
      </div>
			</div>
			<p>
The cursor and end label names are generated to be unique by the FOR expansion.
</p>
		<br />
		
			<a name="setstmt" />
    <h3>9.7.12. SET statement</h3>
			<div>
      <pre class="programlisting">
Set_statement:
	SET option &#39;=&#39; scalar_exp
	| SET option OFF
	| SET option ON
	;

option:
	ISOLATION
	| LOCK_ESCALATION_PCT
	| TRIGGERS
	| PARAM_BATCH
	;
</pre>
    </div>
			<p>The SET statement sets an option to a value. Options may control trigger
invocation, transaction isolation and other settable parameters of
the engine. A SET inside a procedure takes effect inside the procedure
and invoked procedures, counting from time of execution.  Control must
pass through the SET statement for it to take effect, i.e. SET is not
a declaration. The effect of a SET does typically not persist across
procedure return.
</p>
			<p>
A SET given at top level, i.e. directly executed and by a client as the
statement of a SQLExecute sets an option at the connection level. This
may only be reversed by another SET.
</p>
			<p>
The option may be:
</p>
		<br />
		
			<a name="settriggers" />
    <h3>9.7.13. SET Triggers</h3>
			<p>
A value of OFF or 0 causes triggers not to be invoked even if there may
be applicable triggers.  This is mostly useful for controlling recursion
of triggers or for debugging triggers.
</p>
			<p>The value of TRIGGERS is passed into called procedures but other options are not.
</p>
			<div class="tip">
				<div class="tiptitle">See Also:</div>
				<p>
        <a href="SETstmt.html">SET statement.</a>
      </p>
			</div>
		<br />
	<table border="0" width="90%" id="navbarbottom">
    <tr>
        <td align="left" width="33%">
          <a href="EXCEPTIONS.html" title="Exception Semantics">Previous</a>
          <br />Exception Semantics</td>
     <td align="center" width="34%">
          <a href="sqlprocedures.html">Chapter Contents</a>
     </td>
        <td align="right" width="33%">
          <a href="EXECSQLPROCSELECT.html" title="Execute Stored Procedures via SELECT statement">Next</a>
          <br />Execute Stored Procedures via SELECT statement</td>
    </tr>
    </table>
  </div>
  <div id="footer">
    <div>Copyright© 1999 - 2009 OpenLink Software All rights reserved.</div>
   <div id="validation">
    <a href="http://validator.w3.org/check/referer">
        <img src="http://www.w3.org/Icons/valid-xhtml10" alt="Valid XHTML 1.0!" height="31" width="88" />
    </a>
    <a href="http://jigsaw.w3.org/css-validator/">
        <img src="http://jigsaw.w3.org/css-validator/images/vcss" alt="Valid CSS!" height="31" width="88" />
    </a>
   </div>
  </div>
 </body>
</html>