HELPLIB.HLB  —  RDML72  Statements  AVERAGE
    Determines the arithmetic mean of values for all records
    specified by a record selection expression.

1  –  Examples

    The following programs demonstrate the use of the AVERAGE
    function in a display statement. These programs:

    o  Use a record selection expression to form a record stream from
       the view CURRENT_INFO, consisting of the records for which the
       value in the SALARY field is greater than 50000.00

    o  Calculate the average salary for these selected records

    o  Print this average

1.1  –  C Example

    #include <stdio.h>
    DATABASE PERS = FILENAME "PERSONNEL";

    double mean;
    main()
    {
    READY PERS;
    START_TRANSACTION READ_ONLY;

    GET
     mean = AVERAGE CI.SALARY OF CI IN CURRENT_INFO
            WITH CI.SALARY > 50000.00;
    END_GET;

    COMMIT;

    printf ("Average is: %f\n",mean);

    FINISH;
    }

1.2  –  Pascal Example

    program average_function (input,output);
    DATABASE PERS = FILENAME 'PERSONNEL';

    var
    mean : double;
    begin
    READY PERS;
    START_TRANSACTION READ_ONLY;

    GET
      mean = AVERAGE SH.SALARY_AMOUNT OF SH IN SALARY_HISTORY
             WITH SH.SALARY_AMOUNT > 50000.00;
    END_GET;

    COMMIT;

    writeln ('Average is: ', mean:10:2);

    FINISH;
    end.

2  –  Format

  (B)0
  qq> AVERAGE qqqqwqqqqqqqqqqqqqqqqqqqqqwqqqqqqqqqqqqqqqqqqqqqqqqqqk
                  mqq> handle-options qqj                          x
                                                                   x
   lqqqqqqqqqqqqqqqqqqqqqqqqqqq<qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
   x
   mqqqqqqqqqqqq value-expr qqqqqqq> OF qqqqqqqqq> rse qqqqqqqqqqq>

  (B)0handle-options =

  q> ( qwqqqqqq>  REQUEST_HANDLE  qqqqq>  var qqqqqqqqwq> ) q>
        tqqqqqq> TRANSACTION_HANDLE qqq>  var qqqqqqqqu
        mqqqqqq> REQUEST_HANDLE q> var q> , qqqqqqqk  x
          lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj  x
          mqqqq> TRANSACTION_HANDLE q> var qqqqqqqqqqqj

2.1  –  Format arguments

    value-expr             A value expression. A symbol or a string
                           of symbols used to calculate a value. When
                           you use a value expression in a statement,
                           Oracle Rdb calculates the value associated
                           with the expression and uses that value
                           when executing the statement.

    rse                    A record selection expression. A phrase
                           that defines specific conditions that
                           individual records must meet before
                           Oracle Rdb includes them in a record stream.

    handle-options         A request handle, a transaction handle, or
                           both.

    REQUEST_HANDLE var     The REQUEST_HANDLE keyword followed by a
                           host language variable. A request handle
                           identifies a compiled Oracle Rdb request.
                           If you do not supply a request handle
                           explicitly, RDML associates a unique
                           request handle for the compiled request.

    TRANSACTION_HANDLE     The TRANSACTION_HANDLE keyword followed by
    var                    a host language variable. A transaction
                           handle identifies a transaction. If
                           you do not supply a transaction handle
                           explicitly, RDML uses the default
                           transaction handle.
Close Help