1
1
<!--
2
- $Header: /cvsroot/pgsql/doc/src/sgml/Attic/plsql.sgml,v 2.29 2001/05/08 02:53:24 tgl Exp $
2
+ $Header: /cvsroot/pgsql/doc/src/sgml/Attic/plsql.sgml,v 2.30 2001/05/11 06:10:44 tgl Exp $
3
3
-->
4
4
5
5
<chapter id="plpgsql">
@@ -396,12 +396,13 @@ user_id CONSTANT INTEGER := 10;
396
396
</sect3>
397
397
398
398
<sect3 id="plpgsql-description-passed-vars">
399
- <title>Variables Passed to Functions</title>
399
+ <title>Parameters Passed to Functions</title>
400
400
401
401
<para>
402
- Variables passed to functions are named with the identifiers
402
+ Parameters passed to functions are named with the identifiers
403
403
<literal>$1</literal>, <literal>$2</literal>,
404
- etc. (maximum is 16). Some examples:
404
+ etc. Optionally, aliases can be declared for the <literal>$n</literal>
405
+ parameter names for increased readability. Some examples:
405
406
<programlisting>
406
407
CREATE FUNCTION sales_tax(REAL) RETURNS REAL AS '
407
408
DECLARE
437
438
<variablelist>
438
439
<varlistentry>
439
440
<term>
440
- %TYPE
441
+ <replaceable>variable</replaceable> %TYPE
441
442
</term>
442
443
<listitem>
443
444
<para>
447
448
values. For example, let's say you have a column
448
449
named <type>user_id</type> in your
449
450
<type>users</type> table. To declare a variable with
450
- the same datatype as users you do :
451
+ the same datatype as users.user_id you write :
451
452
<programlisting>
452
- user_id users.user_id%TYPE;
453
+ user_id users.user_id%TYPE;
453
454
</programlisting>
454
455
</para>
455
456
@@ -467,30 +468,31 @@ user_id users.user_id%TYPE;
467
468
468
469
<varlistentry>
469
470
<term>
470
- <replaceable>name</replaceable> <replaceable> table</replaceable>%ROWTYPE;
471
+ <replaceable>table</replaceable>%ROWTYPE
471
472
</term>
472
473
<listitem>
473
474
<para>
474
- Declares a row with the structure of the given
475
- table. <replaceable>table</replaceable> must be an existing
475
+ <type>%ROWTYPE</type> provides the composite datatype corresponding
476
+ to a whole row of the specified table.
477
+ <replaceable>table</replaceable> must be an existing
476
478
table or view name of the database. The fields of the row are
477
479
accessed in the dot notation. Parameters to a function can be
478
480
composite types (complete table rows). In that case, the
479
- corresponding identifier $n will be a rowtype, but it must be
480
- aliased using the ALIAS command described above .
481
+ corresponding identifier $n will be a rowtype, and fields can
482
+ be selected from it, for example <literal>$1.user_id</literal> .
481
483
</para>
482
484
483
485
<para>
484
- Only the user attributes of a table row are accessible in the
485
- row, no OID or other system attributes (because the row could
486
- be from a view). The fields of the rowtype inherit the
486
+ Only the user-defined attributes of a table row are accessible in a
487
+ rowtype variable, not OID or other system attributes (because the
488
+ row could be from a view). The fields of the rowtype inherit the
487
489
table's field sizes or precision for <type>char()</type>
488
490
etc. data types.
489
491
</para>
490
492
<programlisting>
491
493
DECLARE
492
494
users_rec users%ROWTYPE;
493
- user_id users%TYPE;
495
+ user_id users.user_id %TYPE;
494
496
BEGIN
495
497
user_id := users_rec.user_id;
496
498
...
0 commit comments