Results 1 to 1 of 1
  1. #1
    Join Date
    Jan 2004
    Posts
    4

    Angry Unanswered: Insert An Array With Oci Into Oracle Tables

    Hello everybody!!

    My problem is to pass many arrays from a program in C into Oracle Tables..
    I'm using OCI and plsql..

    I don't know what is the faster way to do this... i try this..

    First i create table with variable names

    text *pl_sql2 = (text *)
    "Declare
    stmt varchar2(50);
    Begin
    stmt := 'Create Table ' ||:mykey|| '(val Number)';
    execute immediate stmt;
    end;";
    using

    (void) OCIStmtPrepare(mystmthp2,myerrhp,(text *) pl_sql2, (ub4) strlen((const char *) pl_sql2), OCI_NTV_SYNTAX, OCI_DEFAULT);

    (void) OCIBindByName(mystmthp2,&bnd2,myerrhp, (text *) ":mykey", (sb4) strlen((char *) ":mykey"), (ub1 *) mykey, (sword) strlen(mykey)*sizeof(mykey), SQLT_STR, (dvoid *) 0, (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);

    (void) OCIStmtExecute(mysvchp,mystmthp2,myerrhp,(ub4) 1,(ub4) 0, (OCISnapshot *) NULL, (OCISnapshot *) NULL, (ub4) OCI_COMMIT_ON_SUCCESS);

    then i must pass array values and i use the following plsql call

    text *pl_sql = (text *) "Declare
    stmt varchar2(50);
    Begin
    stmt := 'Insert into ' ||:mykey|| ' Values(:int_arr)';
    execute immediate stmt; end;";
    using

    (void) OCIStmtPrepare(mystmthp,myerrhp,(text *) pl_sql, (ub4) strlen((const char *) pl_sql), OCI_NTV_SYNTAX, OCI_DEFAULT);

    (void) OCIBindByName(mystmthp,&bnd[0],myerrhp, (text *) ":mykey", (sb4) strlen((char *) ":mykey"), (ub1 *) mykey, (sword) strlen(mykey)*sizeof(mykey), SQLT_STR, (dvoid *) 0, (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);

    (void) OCIBindByName(mystmthp,&bnd[1],myerrhp, (text *) ":int_arr", (sb4) strlen((char *) ":int_arr"), (dvoid *) &int_arr[0], (sb4) sizeof(int_arr[0]), SQLT_UIN, (dvoid *) 0, (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);

    (void) OCIStmtExecute(mysvchp,mystmthp,myerrhp,(ub4) size, (ub4) 0, (OCISnapshot *) 0, (OCISnapshot *) 0, (ub4) OCI_COMMIT_ON_SUCCESS);

    But i've got 2 errors on the second bind of int_arr and stmtexecute..
    The tables are created but are empty... what are the problem, is there anyone that help me please??
    Last edited by Hellowuin; 01-07-04 at 12:43.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •