谢谢!!!

解决方案 »

  1.   

    Example - Cursor variables
    Since Version 7.2 Oracle supports cursor variables. These variables are a reference to a cursor for a select statement that is defined and opened on the server. They offer the following advantages:
     Cursors are defined and maintained on a central point on the server
     An end-user needs only execute privileges on the procedure, not on the underlying objects of the cursors
    Using a cursor variable as a TOracleQuery
    Because a cursor variable is equivalent to a TOracleQuery with a select statement, DOA implements the cursor variable type as a TOracleQuery. To use a cursor variable, you need at least two TOracleQuery components: one with a PL/SQL block to call the procedure that opens the cursor, and one for the cursor itself:
    begin
      with Query1 do
      begin
        Clear;
        SQL.Add('begin');
        SQL.Add('  employee.opencursor(:p_empcursor, :p_order)');
        SQL.Add('end;');
        DeclareVariable('p_empcursor', otCursor);
        DeclareVariable('p_order', otString);
        SetComplexVariable('p_empcursor', CursorQuery);
        SetVariable('p_order', 'ename');
        Execute;
      end;
      with CursorQuery do
      begin
        Execute;
        while not Eof do
        begin
          Memo.Items.Add(Field('ename'));
          Next;
        end;
      end;
    end;The packaged procedure employee.opencursor might look like this:
    type t_empcursor is ref cursor return emp%rowtype;procedure getcursor(p_empcursor in out t_empcursor, p_order in varchar2) is
    begin
      if p_order = 'ename' then
        open p_empcursor for select * from emp order by ename;
      elsif p_order = 'empno'
        open p_empcursor for select * from emp order by empno;
      else
        open p_empcursor for select * from emp;
      end if;
    end;In this example, Query1 calls the packaged function employee.opencursor to open a cursor to select all employees in a certain order. The CursorQuery is assigned to the p_empcursor variable. You need to use the SetComplexVariable method for this. Next, all rows are fetched and the employee names are displayed in a memo.