|
1 | 1 | <!--
|
2 |
| -$Header: /cvsroot/pgsql/doc/src/sgml/Attic/plsql.sgml,v 2.32 2001/05/17 21:50:16 petere Exp $ |
| 2 | +$Header: /cvsroot/pgsql/doc/src/sgml/Attic/plsql.sgml,v 2.33 2001/05/22 13:52:27 momjian Exp $ |
3 | 3 | -->
|
4 | 4 |
|
5 | 5 | <chapter id="plpgsql">
|
@@ -880,12 +880,11 @@ RETURN <replaceable>expression</replaceable>
|
880 | 880 | <title>Conditional Control: IF statements</title>
|
881 | 881 |
|
882 | 882 | <para>
|
883 |
| - <function>IF</function> statements let you take action |
884 |
| - according to certain conditions. PL/pgSQL has three forms of |
885 |
| - IF: IF-THEN, IF-THEN-ELSE, IF-THEN-ELSE IF. NOTE: All |
886 |
| - PL/pgSQL IF statements need a corresponding <function>END |
887 |
| - IF</function> statement. In ELSE-IF statements you need two: |
888 |
| - one for the first IF and one for the second (ELSE IF). |
| 883 | + <function>IF</function> statements let you execute commands based on |
| 884 | + certain conditions. PL/PgSQL has four forms of IF: IF-THEN, IF-THEN-ELSE, |
| 885 | + IF-THEN-ELSE IF, IF-THEN-ELSIF-THEN-ELSE. NOTE: All PL/PgSQL IF statements need |
| 886 | + a corresponding <function>END IF</function> clause. With ELSE-IF statements, |
| 887 | + you need two: one for the first IF and one for the second (ELSE IF). |
889 | 888 | </para>
|
890 | 889 |
|
891 | 890 | <variablelist>
|
@@ -979,6 +978,41 @@ END IF;
|
979 | 978 | </para>
|
980 | 979 | </listitem>
|
981 | 980 | </varlistentry>
|
| 981 | + |
| 982 | + <varlistentry> |
| 983 | + <term> |
| 984 | + IF-THEN-ELSIF-ELSE |
| 985 | + </term> |
| 986 | + |
| 987 | + <listitem> |
| 988 | + <para> |
| 989 | + IF-THEN-ELSIF-ELSE allows you test multiple conditions |
| 990 | + in one statement. Internally it is handled as nested |
| 991 | + IF-THEN-ELSE-IF-THEN commands. The optional ELSE |
| 992 | + branch is executed when none of the conditions are met. |
| 993 | + </para> |
| 994 | + |
| 995 | + <para> |
| 996 | + Here is an example: |
| 997 | + </para> |
| 998 | + |
| 999 | +<programlisting> |
| 1000 | +IF number = 0 THEN |
| 1001 | + result := ''zero''; |
| 1002 | +ELSIF number < 0 THEN |
| 1003 | + result := ''negative''; |
| 1004 | +ELSIF number > 0 THEN |
| 1005 | + result := ''negative''; |
| 1006 | +ELSE |
| 1007 | + -- now it seems to be NULL |
| 1008 | + result := ''NULL''; |
| 1009 | +END IF; |
| 1010 | +</programlisting> |
| 1011 | + </para> |
| 1012 | + </listitem> |
| 1013 | + </varlistentry> |
| 1014 | + |
| 1015 | + |
982 | 1016 | </variablelist>
|
983 | 1017 | </sect3>
|
984 | 1018 |
|
|
0 commit comments