Author: jstephens
Date: 2008-03-08 20:35:51 +0100 (Sat, 08 Mar 2008)
New Revision: 10175
Log:
Added stored routine examples using IF staments (user comments)
Modified:
trunk/refman-5.0/stored-procedures.xml
trunk/refman-5.1/stored-procedures.xml
trunk/refman-6.0/stored-procedures.xml
Modified: trunk/refman-5.0/stored-procedures.xml
===================================================================
--- trunk/refman-5.0/stored-procedures.xml 2008-03-08 17:34:41 UTC (rev 10174)
+++ trunk/refman-5.0/stored-procedures.xml 2008-03-08 19:35:51 UTC (rev 10175)
Changed blocks: 1, Lines Added: 65, Lines Deleted: 0; 2096 bytes
@@ -2028,6 +2028,71 @@
<remark role="help-description-end"/>
+ <para>
+ An <literal>IF ... END IF</literal> block — like all
+ other flow-control blocks used within stored routines —
+ must be terminated with a semicolon, as shown in this example:
+
+<programlisting>
+DELIMITER //
+
+CREATE FUNCTION SimpleCompare(n INT, m INT) RETURNS VARCHAR(20)
+ BEGIN
+ DECLARE s VARCHAR(20);
+
+ IF n > m THEN s = '>';
+ ELSEIF n = m THEN s = '=';
+ ELSE s = '<'
+ END IF;
+
+ s = CONCAT(n, ' ', s, ' ', m);
+
+ RETURN s;
+ END //
+
+DELIMITER ;
+</programlisting>
+ </para>
+
+ <para>
+ As with other flow-control constructs, <literal>IF ... END
+ IF</literal> blocks may be nested within other flow-control
+ constructs, including other <literal>IF</literal> statements.
+ Each <literal>IF</literal> must be terminated by its own
+ <literal>END IF</literal> followed by a semicolon. You can use
+ indentation to make nested flow-control blocks more easily
+ readable by humans (although this is not required by MySQL),
+ as shown here:
+
+<programlisting>
+DELIMITER //
+
+CREATE FUNCTION VerboseCompare (n INT, m INT) RETURNS VARCHAR(50)
+ BEGIN
+ DECLARE s VARCHAR(50);
+
+ IF n = m THEN SET s = 'equals';
+ ELSE
+ IF n > m THEN SET s = 'greater';
+ ELSE SET s = 'less';
+ END IF;
+
+ SET s = CONCAT('is ', s, ' than');
+ END IF;
+
+ SET s = CONCAT(n, ' ', s, ' ', m, '.');
+
+ RETURN s;
+ END //
+
+DELIMITER ;
+</programlisting>
+
+ In this example, the inner <literal>IF</literal> is evaluated
+ only if <literal>n</literal> is not equal to
+ <literal>m</literal>.
+ </para>
+
</section>
<section id="case-statement">
Modified: trunk/refman-5.1/stored-procedures.xml
===================================================================
--- trunk/refman-5.1/stored-procedures.xml 2008-03-08 17:34:41 UTC (rev 10174)
+++ trunk/refman-5.1/stored-procedures.xml 2008-03-08 19:35:51 UTC (rev 10175)
Changed blocks: 1, Lines Added: 65, Lines Deleted: 0; 2093 bytes
@@ -1986,6 +1986,71 @@
<remark role="help-description-end"/>
+ <para>
+ An <literal>IF ... END IF</literal> block — like all
+ other flow-control blocks used within stored routines —
+ must be terminated with a semicolon, as shown in this example:
+
+<programlisting>
+DELIMITER //
+
+CREATE FUNCTION SimpleCompare(n INT, m INT) RETURNS VARCHAR(20)
+ BEGIN
+ DECLARE s VARCHAR(20);
+
+ IF n > m THEN s = '>';
+ ELSEIF n = m THEN s = '=';
+ ELSE s = '<'
+ END IF;
+
+ s = CONCAT(n, ' ', s, ' ', m);
+
+ RETURN s;
+ END //
+
+DELIMITER ;
+</programlisting>
+ </para>
+
+ <para>
+ As with other flow-control constructs, <literal>IF ... END
+ IF</literal> blocks may be nested within other flow-control
+ constructs, including other <literal>IF</literal> statements.
+ Each <literal>IF</literal> must be terminated by its own
+ <literal>END IF</literal> followed by a semicolon. You can use
+ indentation to make nested flow-control blocks more easily
+ readable by humans (although this is not required by MySQL),
+ as shown here:
+
+<programlisting>
+DELIMITER //
+
+CREATE FUNCTION VerboseCompare (n INT, m INT) RETURNS VARCHAR(50)
+ BEGIN
+ DECLARE s VARCHAR(50);
+
+ IF n = m THEN SET s = 'equals';
+ ELSE
+ IF n > m THEN SET s = 'greater';
+ ELSE SET s = 'less';
+ END IF;
+
+ SET s = CONCAT('is ', s, ' than');
+ END IF;
+
+ SET s = CONCAT(n, ' ', s, ' ', m, '.');
+
+ RETURN s;
+ END //
+
+DELIMITER ;
+</programlisting>
+
+ In this example, the inner <literal>IF</literal> is evaluated
+ only if <literal>n</literal> is not equal to
+ <literal>m</literal>.
+ </para>
+
</section>
<section id="case-statement">
Modified: trunk/refman-6.0/stored-procedures.xml
===================================================================
--- trunk/refman-6.0/stored-procedures.xml 2008-03-08 17:34:41 UTC (rev 10174)
+++ trunk/refman-6.0/stored-procedures.xml 2008-03-08 19:35:51 UTC (rev 10175)
Changed blocks: 1, Lines Added: 65, Lines Deleted: 0; 2093 bytes
@@ -1984,6 +1984,71 @@
<remark role="help-description-end"/>
+ <para>
+ An <literal>IF ... END IF</literal> block — like all
+ other flow-control blocks used within stored routines —
+ must be terminated with a semicolon, as shown in this example:
+
+<programlisting>
+DELIMITER //
+
+CREATE FUNCTION SimpleCompare(n INT, m INT) RETURNS VARCHAR(20)
+ BEGIN
+ DECLARE s VARCHAR(20);
+
+ IF n > m THEN s = '>';
+ ELSEIF n = m THEN s = '=';
+ ELSE s = '<'
+ END IF;
+
+ s = CONCAT(n, ' ', s, ' ', m);
+
+ RETURN s;
+ END //
+
+DELIMITER ;
+</programlisting>
+ </para>
+
+ <para>
+ As with other flow-control constructs, <literal>IF ... END
+ IF</literal> blocks may be nested within other flow-control
+ constructs, including other <literal>IF</literal> statements.
+ Each <literal>IF</literal> must be terminated by its own
+ <literal>END IF</literal> followed by a semicolon. You can use
+ indentation to make nested flow-control blocks more easily
+ readable by humans (although this is not required by MySQL),
+ as shown here:
+
+<programlisting>
+DELIMITER //
+
+CREATE FUNCTION VerboseCompare (n INT, m INT) RETURNS VARCHAR(50)
+ BEGIN
+ DECLARE s VARCHAR(50);
+
+ IF n = m THEN SET s = 'equals';
+ ELSE
+ IF n > m THEN SET s = 'greater';
+ ELSE SET s = 'less';
+ END IF;
+
+ SET s = CONCAT('is ', s, ' than');
+ END IF;
+
+ SET s = CONCAT(n, ' ', s, ' ', m, '.');
+
+ RETURN s;
+ END //
+
+DELIMITER ;
+</programlisting>
+
+ In this example, the inner <literal>IF</literal> is evaluated
+ only if <literal>n</literal> is not equal to
+ <literal>m</literal>.
+ </para>
+
</section>
<section id="case-statement">
| Thread |
|---|
| • svn commit - mysqldoc@docsrva: r10175 - in trunk: refman-5.0 refman-5.1 refman-6.0 | jon | 8 Mar |