Ora8SetString Function

Action

Assigns a string to the program variable that is bound to the specified place holder in the SQL statement or PL/SQL block. The place holder is identified by the name or the number specified in the SQL statement or PL/SQL block. This function is used to assign values to both scalar and array program variables.

Using this function, any of the following data types can be assigned to the program variable that is bound to the specified place holder:

  • SQLT_STR
  • SQLT_CHR
  • SQLT_VCS
  • SQLT_LVC
  • SQLT_AFC
  • SQLT_AVC
  • SQLT_LNG
  • SQLT_RDD

Include file

Ora8.bdh

Syntax

Ora8SetString( in hStmt   : number,
               in sSqlVar : string,
               in sString : string,
               in nIndex  : number optional): boolean;

Return value

  • true if successful

  • false otherwise. In this case, you can use the Ora8OciError function to retrieve the Oracle OCI error code

Parameter Description
hStmt Statement handle.
sSqlVar Name of the place holder in the SQL statement or PL/SQL block. This parameter must include the preceding colon identifying it as a place holder.
sString String that is assigned to the program variable that is bound to the specified place holder in the SQL statement or PL/SQL block.
nIndex Array index (optional). For array binding operations, this parameter specifies the array index of the program variable.

Example

var
  ghEnv0        : number;
  ghError0      : number;
  ghStmt0       : number;
  ghSvcCtx0     : number;

dcltrans
  transaction TMain
  begin
    Ora8Init(ghEnv0, OCI_DEFAULT);
    Ora8HandleAlloc(ghEnv0, ghError0, OCI_HTYPE_ERROR);
    Ora8Logon(ghEnv0, ghSvcCtx0, "user", "password", "orclnet2");

    Ora8HandleAlloc(ghEnv0, ghStmt0, OCI_HTYPE_STMT);
    Ora8StmtPrepare(ghStmt0, sqlInsert, OCI_NTV_SYNTAX);

    // bind array containing two elements
    Ora8Bind(ghStmt0, ":name", SQLT_CHR, 32, 2);
    Ora8Bind(ghStmt0, ":age", SQLT_INT, 0, 2);

    // set values
    Ora8SetString(ghStmt0, ":name", "Bob", 1);
    Ora8SetInt(ghStmt0, ":age", 25, 1);

    Ora8SetString(ghStmt0, ":name", "Marcy", 2);
    Ora8SetInt(ghStmt0, ":age", 33, 2);

    Ora8StmtExecute(ghSvcCtx0, ghStmt0);

    Ora8HandleFree(ghStmt0, OCI_HTYPE_STMT);
    Ora8Logoff(ghSvcCtx0);
    Ora8HandleFree(ghError0, OCI_HTYPE_ERROR);
    Ora8HandleFree(ghEnv0, OCI_HTYPE_ENV);
  end TMain;

dclsql
  sqlInsert:
    INSERT INTO persons (name, age) VALUES (:name, :age);