Working with Cursors in SQL Query Execution Results

If execution of the command or stored procedure results in the cursor, to get it, create a parameter and set DalParamDirection.RefCursor as a destination in the IDalCommand.Params collection. After executing the command cast value of the parameter to the IDalCursor type to work with the obtained cursor:

Var
    //...
    ORCLConnect: IDalConnection;
    Command: IDalCommand;
    Param: IDalCommandParam;
    ResultCursor: IDalCursor;
    //...
Begin
    //...
    Command := ORCLConnect.CreateCommand;
    //Execute function
    Command.SQL := "Func_1";
    Command.Type := DalCommandType.StoredProcedure;
    //Create a parameter, in which the cursor as the function execution result is available
    Param := Command.Params.Add("Result");
    Param.Direction := DalParamDirection.RefCursor;
    Command.Execute;
    Command.Close;
    ResultCursor := Param.Value As IDalCursor;
    //Further work with obtained cursor
    //...

Cursor in Field Values

If an arbitrary structure data set is result of executing a command or stored procedure, some fields may also contain data cursors as values. The type of data will be set for such fields, which is DbDataDomain.RefCur. To work with data of these fields, cast the field value in the current record to the IDalCursor type:

Var
    //...
    ORCLConnect: IDalConnection;
    Command: IDalCommand;
    Param: IDalCommandParam;
    ResultCursor, FieldCursor: IDalCursor;
    Field: IDalCursorField;
    v: Variant;
    //...
Begin
    //...
    Command := ORCLConnect.CreateCommand;
    //Execute function
    Command.SQL := "Func_1";
    Command.Type := DalCommandType.StoredProcedure;
    //Create a parameter, in which the function execution result is available
    Param := Command.Params.Add("Result");
    Param.Direction := DalParamDirection.RefCursor;
    Command.Execute;
    Command.Close;
    ResultCursor := Param.Value As IDalCursor;
    While Not ResultCursor.Eof Do
        For Each Field In ResultCursor.Fields Do
            If Field.DataDomain = DbDataDomain.RefCur Then
                FieldCursor := Field.Value As IDalCursor;
               //Work with the cursor, which is obtained from field value
                //...
            Else
                v := Field.Value;
               //Work with field value
            End If;
        End For;
        ResultCursor.Next;
    End While;
    //...

See also:

Executing Stored Procedures and Functions