Library /sys$common/syshlp/HELPLIB.HLB  —  RDML72  Statements  FIRST_FROM
    The FIRST FROM expression forms a record stream as specified
    by the record selection expression. If at least one record in
    the stream matches the record selection expression, Oracle Rdb
    uses the values stored in the first record of the record stream
    to evaluate the value expression. If there are no matches, you
    receive a runtime error.

    The FIRST FROM value expression can perform the equivalent of a
    table lookup when you are sure that the value you want to find is
    unique in a relation.

1  –  Examples

    The following programs demonstrate the use of the FIRST FROM
    clause. The programs find the first record in the JOBS relation
    with the value "Company President" in the field JOB_TITLE. Using
    this record's value for JOB_CODE, these programs create a record
    stream containing the records in the CURRENT_JOB relation that
    have this same job code. The programs print the value that the
    first record from this record stream holds in the LAST_NAME
    field.

1.1  –  C Example

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

    DECLARE_VARIABLE name SAME AS PERS.CURRENT_JOB.LAST_NAME;
    main()
    {
    READY PERS;
    START_TRANSACTION READ_ONLY;

    GET
     name =  FIRST C.LAST_NAME FROM C IN CURRENT_JOB
             WITH C.JOB_CODE = FIRST J.JOB_CODE FROM J IN JOBS
             WITH J.JOB_TITLE = "Company President"
             SORTED BY C.JOB_CODE;
    END_GET;

    printf ("Last name is %s", name);

    COMMIT;
    FINISH;
    }

1.2  –  Pascal Example

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

    DECLARE_VARIABLE name SAME AS PERS.CURRENT_JOB.LAST_NAME;

    begin
    READY PERS;
    START_TRANSACTION READ_ONLY;

    GET
      name =  FIRST C.LAST_NAME FROM C IN CURRENT_JOB
              WITH C.JOB_CODE = FIRST J.JOB_CODE FROM J IN JOBS
              WITH J.JOB_TITLE = 'Company President'
              SORTED C.JOB_CODE;
    END_GET;

    writeln ('Last name is: ', name);

    COMMIT;
    FINISH;
    end.

2  –  Format

  (B)0first-from-expr =

    qqq> FIRST qwqqqqqqqqq>qqqqqqqqqqwq>  value-expr qqq> FROM qqqk
                mq> handle-options qqj                            x
                                                                  x
                lqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqj
                x
                mqqqqqq>     rse  qqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqqq>

  (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