OraFetch Function

Action

Performs a specified number of fetch operations in order to retrieve data from a SQL query. This function is used to fetch both single and multiple rows.

Afterwards, the following functions can be used to retrieve the fetched data:

  • OraGetFloat
  • OraGetInt
  • OraGetString
  • OraGetValue

Include file

Ora.bdh

Syntax

OraFetch( in  cCursor     : cursor,
          in  nIterations : number optional,
          in  nBatchSize  : number optional,
          out nFetched    : number optional ): boolean;

Return value

  • true if successful

  • false either if an error occurred during the fetch operation or if the number of rows actually fetched is not equal to the specified number of rows to fetch.

Parameter Description
cCursor Cursor associated with a database connection
nIterations

Number of iterations to perform (optional). Predefined options are:

  • ORA_FETCH_ALL. Repeat the fetch operation until all rows have been fetched

The default option is to perform a single iteration

nBatchSize Number of rows to fetch per iteration (optional). The default option is to fetch a single row per iteration
nFetched Variable receiving the actual number of rows fetched (optional)

Example

var
  hConnection : number;
  cCursor : cursor;

dcltrans
  transaction TMain
  const    MAX_ROWS := 1000; // maximum number of rows
  var
    nFetched, i, nAge : number;
    sName : string;
  begin
    OraLogon(hConnection, "user", "password", "orclnet2");
    OraOpen(cCursor, hConnection);
    OraParse(cCursor, sqlSelect);
    OraDefine(cCursor, 1, SQLT_CHR, 32);
    OraDefine(cCursor, 2, SQLT_INT);
    // first possibility to fetch all rows
    // in this case, nFetched must be smaller than MAX_ROWS
    OraExec(cCursor);
    OraFetch(cCursor, 1, MAX_ROWS, nFetched);
 
    for i := 1 to nFetched do
      sName := OraGetString(cCursor, "1", i);
      nAge := OraGetInt(cCursor, "2", i);
      write(sName, 32); write(nAge, 5); writeln;
    end;

     // second possibility to fetch all data
    OraExec(cCursor);

        while OraFetch(cCursor) do
      sName := OraGetString(cCursor, "1");
      nAge := OraGetInt(cCursor, "2");
      write(sName, 32);
 write(nAge, 5); writeln;
    end;

    OraClose(cCursor);
    OraLogoff(hConnection);
  end TMain;

dclsql
  sqlSelect:
  SELECT * FROM persons;

Output

Howard 33Michael 44Bobby 61Sara 38

Sample scripts

OraArrayFetch.bdf, OraSample.bdf

See also

Oracle's Programmer's Guide to Oracle Call Interface for Wrapped Oracle functions: ofetch, ofen