Working with command
Previous  Index  Next

OCL lets you effortlessly execute your SQL or PL/SQL statements which may return recordsets for further processing in your application.
OraCommand class provides methods to execute either complete SQL statement or just the name of the Oracle table or stored procedure.
OCL allows you to call any stored procedure or function easily, including procedures and functions in packages. It is enough to know only the name. To execute stored procedure set command type to ctStoredProc before calling execute method. For example, to insert new record into DEPT table with DEPT_INSERT procedure:

  CREATE OR REPLACE
  PROCEDURE DEPT_INSERT (
    p_DeptNo NUMBER,
    p_DName VARCHAR2,
    p_Loc VARCHAR2)
  is
  begin
    INSERT INTO Scott.Dept(DeptNo, DName, Loc)
      VALUES (p_DeptNo, p_DName, p_Loc); 
  end;

you can write this code:

  OraConnection connection;
  OraCommand cmd;
  . . .
  cmd.setConnection(connection);
  cmd.setCommandText("DEPT_INSERT");
  cmd.setCommandType(ctStoredProc);
  cmd.param("p_DeptNo").setInt(50);
  cmd.param("p_DName").setString("DEVELOPMENT");
  cmd.param("p_Loc").setString("LONDON");
  cmd.execute();

If you call stored function you can access to function result by parameter with "Result" name.

OCL gives ability to fetch rows from REF CURSOR parameter. This feature is available with OraRecordset. To fetch records from the REF CURSOR parameter call executeQuery method that will return recordset for this cursor. In proc demo project you can find an example of how to work with this type of procedures.

See Also

OraCommand::setCommandText, OraCommand::setCommandType, OraCommand::param, OraCommand::execute, Proc demo project


OCL | Using OCL | Index