Improve discussion of %TYPE and %ROWTYPE.
authorTom Lane
Fri, 11 May 2001 06:10:44 +0000 (06:10 +0000)
committerTom Lane
Fri, 11 May 2001 06:10:44 +0000 (06:10 +0000)
doc/src/sgml/plsql.sgml

index 0bc49b52cafba4299c32d2b334235557156efda9..4e1314c8b9876474f178ed75e02ad428b1135668 100644 (file)
@@ -1,5 +1,5 @@
 
 
  
@@ -396,12 +396,13 @@ user_id CONSTANT INTEGER := 10;
     
 
     
-     <span class="marked">Variable</span>s Passed to Functions
+     <span class="marked">Parameter</span>s Passed to Functions
 
      
-      Variables passed to functions are named with the identifiers
+      Parameters passed to functions are named with the identifiers
       $1$2,
-      etc. (maximum is 16). Some examples:
+      etc.  Optionally, aliases can be declared for the $n
+      parameter names for increased readability.  Some examples:
 
 CREATE FUNCTION sales_tax(REAL) RETURNS REAL AS '
 DECLARE
@@ -437,7 +438,7 @@ END;
      
       
        
-        %TYPE
+        variable%TYPE
        
        
         
@@ -447,9 +448,9 @@ END;
          values. For example, let's say you have a column
          named user_id in your
          users table. To declare a variable with
-         the same datatype as users you do:
+         the same datatype as users.user_id you write:
 
-user_id users.user_id%TYPE;
+user_id   users.user_id%TYPE;
 
         
 
@@ -467,30 +468,31 @@ user_id users.user_id%TYPE;
 
       
        
-        name table%ROWTYPE;
+        table%ROWTYPE
        
        
         
-         Declares a row with the structure of the given
-    table. table must be an existing
+    %ROWTYPE provides the composite datatype corresponding
+    to a whole row of the specified table.
+    table must be an existing
     table or view name of the database. The fields of the row are
     accessed in the dot notation. Parameters to a function can be
     composite types (complete table rows). In that case, the
-    corresponding identifier $n will be a rowtype, but it must be
-    aliased using the ALIAS command described above.
+    corresponding identifier $n will be a rowtype, and fields can
+    be selected from it, for example $1.user_id.
         
 
         
-         Only the user attributes of a table row are accessible in the
-    row, no OID or other system attributes (because the row could
-    be from a view).  The fields of the rowtype inherit the
+         Only the user-defined attributes of a table row are accessible in a
+    rowtype variable, not OID or other system attributes (because the
+    row could be from a view).  The fields of the rowtype inherit the
     table's field sizes or precision for char()
     etc. data types.
         
 
 DECLARE
     users_rec users%ROWTYPE;
-  user_id users%TYPE;
+    user_id users.user_id%TYPE;
 BEGIN
     user_id := users_rec.user_id;
     ...