SQLT_DAT

Alright, got a little problem.
When I use the SQLT_DAT datatype to fetch a date value from a table and the year is < 2000, I get bad values in the second byte of the 7 byte date variable:
Example 1 (date = 1997-FEB-14)
date[0] = 119 (correct)
date[1] = -59 (incorrect, should be 197)
date[2] = 2 (correct)
date[3] = 14 (correct)
Example 2 (date = 1990-JAN-23)
date[0] = 119 (correct)
date[1] = -66 (incorrect, should be 190)
date[2] = 1 (correct)
date[3] = 23 (correct)
Any ideas why I'm getting negative numbers in byte 2? Is my database set up incorrectly? The date does show up correctly when I select the field in SQL*Plus.

The characters should be unsigned, not signed. If you use unsigned chars you'll get the numbers you expect (signed -59 equals unsigned 197, and signed -66 equals unsigned 190).

Similar Messages

  • Help!!!it's not the desired result of oci bulk update!!

    here is demo_update of oci/samples cdemodr1.c,i modified a little,and the other of cdemodr1.c keeps unchanged:
    1.
    give the result:
    after demo_insert
    in4[i] = 400.555 + (float)i;//c4 value
    get the result:
    C1 C4
    1 400.554993
    2 401.554993
    3 402.554993
    4 403.554993
    5 404.554993
    6 405.554993
    7 406.554993
    8 407.554993
    9 408.554993
    10 409.554993
    i expect to update c4 value to:
    in4[i] = 1401.555 + (float)i;
    and get the result:
    C1 C4
    1 1400.554993
    2 1401.554993
    3 1402.554993
    4 1403.554993
    5 1404.554993
    6 1405.554993
    7 1406.554993
    8 1407.554993
    9 1408.554993
    10 1409.554993
    but after my modified demo_update,
    the result is not the expectation,
    the resule is:
    C1 C4
    1 1403.55505
    2 1403.55505
    3 1403.55505
    4 1403.55505
    5 1403.55505
    6 1403.55505
    7 1403.55505
    8 1403.55505
    9 1403.55505
    10 1403.55505
    2.
    table create script:
    create table TAB1
    c1 integer not null
    c2 char(40),
    c3 varchar2(40),
    c4 float,
    c5 decimal,
    c6 decimal(8,3),
    c7 numeric,
    c8 numeric(7,2),
    c9 date,
    c10 raw(40),
    constraint ind_tab1
    organization index;

    3.
    here is my modified demo_update():
    please help me to check out where it goes wrong!!
    thank you!!!
    static sword demo_update(OCISvcCtx svchp, OCIStmt stmthp,
    OCIBind bndhp[], OCIError errhp)
    int i, j;
    int range_size = 3; /* iterations */
    sb4     len;
    * This function updates columns in table TAB1, for certain rows
    * depending on the values of the :low and :high values in
    * in the WHERE clause. It executes this statement 3 times, (3 iterations)
    * each time with a different set of values for :low and :high
    * Thus for each iteration, multiple rows are returned depending
    * on the number of rows that matched the WHERE clause.
    * The rows it updates here are the rows that were inserted by the
    * cdemodr1.sql script.
    /* The Update Statement with RETURNING clause */
    text sqlstmt = (text )
    "UPDATE TAB1 SET C2 = :1, C3 = :1, \
    C4 = :1, C5 = :1, C6 = :1, \
    C7 = :1, C8 = :1, C9 = :1, C10 = :1 \
    /* Prepare the statement */
    if (OCIStmtPrepare(stmthp, errhp, sqlstmt, (ub4)strlen((char *)sqlstmt),
    (ub4) OCI_NTV_SYNTAX, (ub4) OCI_DEFAULT))
    (void) printf("FAILED: OCIStmtPrepare() update\n");
    report_error(errhp);
    return OCI_ERROR;
    /* Initialise the buffers for insertion */
    for (i = 0; i < MAXITER; i++)
    //in1[i] = 300 + i;
    memset((void *)in2, (int) 'a'+i%26, (size_t) 40);
    memset((void *)in3[i], (int) 'A'+i%26, (size_t) 40);
    in4[i] = 1401.555 + (float)i;
    in5[i] = 500 + i;
    in6[i] = 600.280 + (float)i;
    in7[i] = 700 + i;
    in8[i] = 800.620 + (float)i;
    in9[i][0] = 119;
    in9[i][1] = 185 - (ub1)i%10;
    in9[i][2] = (ub1)i%12 + 1;
    in9[i][3] = (ub1)i%25 + 1;
    in9[i][4] = 0;
    in9[i][5] = 0;
    in9[i][6] = 0;
    for (j = 0; j < 40; j++)
    in10[i][j] = (ub1) (i%0x08);
    rowsret[i] =0;
    len = /*sizeof(in1[0]) + */sizeof(in2[0]) + sizeof(in3[0]) + sizeof(in4[0]) + sizeof(in5[0])
         + sizeof(in6[0]) + sizeof(in7[0]) + sizeof(in8[0]) + sizeof(in9[0]) + sizeof(in10[0]);
    /* Bind all the input buffers to place holders (:1, :2. :3, etc ) */
    //if (bind_input(stmthp, bndhp, errhp))
    // return OCI_ERROR;
    if (/*OCIBindByPos(stmthp, &bndhp[0], errhp, (ub4) 10,
    (dvoid *) &in1[0], (sb4) sizeof(in1[0]), SQLT_INT,
    (dvoid *) 0, (ub2 *)0, (ub2 *)0,
    (ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
    ||*/ OCIBindByPos(stmthp, &bndhp[1], errhp, (ub4) 1,
    (dvoid *) in2[0], (sb4) sizeof(in2[0]), SQLT_AFC,
    (dvoid *) 0, (ub2 *)0, (ub2 *)0,
    (ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
    || OCIBindByPos(stmthp, &bndhp[2], errhp, (ub4) 2,
    (dvoid *) in3[0], (sb4) sizeof(in3[0]), SQLT_CHR,
    (dvoid *) 0, (ub2 *)0, (ub2 *)0,
    (ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
    || OCIBindByPos(stmthp, &bndhp[3], errhp, (ub4) 3,
    (dvoid *) &in4[0], (sb4) sizeof(in4[0]), SQLT_FLT,
    (dvoid *) 0, (ub2 *)0, (ub2 *)0,
    (ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
    || OCIBindByPos(stmthp, &bndhp[4], errhp, (ub4) 4,
    (dvoid *) &in5[0], (sb4) sizeof(in5[0]), SQLT_INT,
    (dvoid *) 0, (ub2 *)0, (ub2 *)0,
    (ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
    || OCIBindByPos(stmthp, &bndhp[5], errhp, (ub4) 5,
    (dvoid *) &in6[0], (sb4) sizeof(in6[0]), SQLT_FLT,
    (dvoid *) 0, (ub2 *)0, (ub2 *)0,
    (ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
    || OCIBindByPos(stmthp, &bndhp[6], errhp, (ub4) 6,
    (dvoid *) &in7[0], (sb4) sizeof(in7[0]), SQLT_INT,
    (dvoid *) 0, (ub2 *)0, (ub2 *)0,
    (ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
    || OCIBindByPos(stmthp, &bndhp[7], errhp, (ub4) 7,
    (dvoid *) &in8[0], (sb4) sizeof(in8[0]), SQLT_FLT,
    (dvoid *) 0, (ub2 *)0, (ub2 *)0,
    (ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
    || OCIBindByPos(stmthp, &bndhp[8], errhp, (ub4) 8,
    (dvoid *) in9[0], (sb4) sizeof(in9[0]), SQLT_DAT,
    (dvoid *) 0, (ub2 *)0, (ub2 *)0,
    (ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT)
    || OCIBindByPos(stmthp, &bndhp[9], errhp, (ub4) 9,
    (dvoid *) in10[0], (sb4) sizeof(in10[0]), SQLT_BIN,
    (dvoid *) 0, (ub2 *)0, (ub2 *)0,
    (ub4) 0, (ub4 *) 0, (ub4) OCI_DEFAULT))
    (void) printf("FAILED: OCIBindByPos()\n");
    report_error(errhp);
    return OCI_ERROR;
    if (/*OCIBindArrayOfStruct(bndhp[0], errhp, s1, indsk[0], rlsk[0], rcsk[0])
    ||*/ OCIBindArrayOfStruct(bndhp[1], errhp, s2, indsk[1], rlsk[1], rcsk[1])
    || OCIBindArrayOfStruct(bndhp[2], errhp, s3, indsk[2], rlsk[2], rcsk[2])
    || OCIBindArrayOfStruct(bndhp[3], errhp, s4, indsk[3], rlsk[3], rcsk[3])
    || OCIBindArrayOfStruct(bndhp[4], errhp, s5, indsk[4], rlsk[4], rcsk[4])
    || OCIBindArrayOfStruct(bndhp[5], errhp, s6, indsk[5], rlsk[5], rcsk[5])
    || OCIBindArrayOfStruct(bndhp[6], errhp, s7, indsk[6], rlsk[6], rcsk[6])
    || OCIBindArrayOfStruct(bndhp[7], errhp, s8, indsk[7], rlsk[7], rcsk[7])
    || OCIBindArrayOfStruct(bndhp[8], errhp, s9, indsk[8], rlsk[8], rcsk[8])
    || OCIBindArrayOfStruct(bndhp[9], errhp, s10, indsk[9], rlsk[9], rcsk[9]))
    (void) printf("FAILED: OCIBindArrayOfStruct()\n");
    report_error(errhp);
    return OCI_ERROR;
    (void) printf("\n\n DEMONSTRATING UPDATE....RETURNING \n");
    if (OCIStmtExecute(svchp, stmthp, errhp, (ub4) range_size, (ub4) 0,
    (CONST OCISnapshot*) 0, (OCISnapshot*) 0,
    (ub4) OCI_DEFAULT))
    (void) printf("FAILED: OCIStmtExecute() update\n");
    report_error(errhp);
    return OCI_ERROR;
    /* Commit the changes */
    (void) OCITransCommit(svchp, errhp, (ub4) 0);
    /* Print out the values in the return rows */
    //(void) print_return_data(range_size);
    return OCI_SUCCESS;

  • Problem in using OCIBindByName  for date type column

    Hi,
    Can you please guide me about my following problem?
    I am trying to fetch the data from system table "FLOWS_020100.WWV_FLOW_ACTIVITY_LOG1$" in Oracle Express edition 10.2.0.3 database, using the OCI library on Windows with C++
    This table has a TIMESTAMP column of date type.
    I've the following query as below:
    select TIME_STAMP from FLOWS_020100.WWV_FLOW_ACTIVITY_LOG1$ where TIME_STAMP > to_date('31/OCT/12 23:59:59', 'DD-MON-YY HH24:MI:SS') order by TIME_STAMP asc;
    For this, first I am preparing the query as below:
    select TIME_STAMP from FLOWS_020100.WWV_FLOW_ACTIVITY_LOG1$ where TIME_STAMP > :PKVAL order by TIME_STAMP asc;
    Before calling OCIExecute(), I am setting the PKVAL buffer to following value:
    "to_date('31/OCT/12 23:59:59', 'DD-MON-YY HH24:MI:SS') "
    & calling the OCIBindByName function with data type as SQLT_DATE.
    But when the OCIExecute is called, my program crashes with access violation
    Can you please guide me what is the correct way to pass the date value in query to OCI? How do we bind the date values?
    Thanks in advance for your time and help.
    Best Regards.

    I had a similar problem. TO_DATE doesn't appear to function w/ BindByName or BindByPos.
    You are going to have to bite the bullet and use an actual date.
    Here's an example (I am using two dates in my query):
    int main (int argc, char **argv, char **envp)
    static text invalidQuery = (text )"SELECT f1.my_val, COUNT(f1.my_val) invalid_count, (SELECT COUNT(*) FROM my_db_table f2 WHERE f2.my_val = f1.my_val AND f2.foo_dt = :1 ) total_count FROM my_db_table f1 WHERE f1.foo_dt = :1 AND ( (f1.vld_bar_sw IS NULL OR f1.vld_bar_sw = 'N') OR (f1.vld_foo_sw IS NULL OR f1.vld_foo_sw = 'N') ) group by my_val order by my_val asc";
    OCIDate boundDateVal;
    sb2 inputYear;
    ub1 inputMonth;
    ub1 inputDay;
    char inputYearStr [] = "0000";
    char inputMonthStr [] = "00";
    char inputDayStr [] = "00";
    /* I get and validate the date as input, but you can set it however you'd like */
    inputYear = (sb2) (atoi (inputYearStr));
    inputMonth = (ub1) (atoi(inputMonthStr));
    inputDay = (ub1) (atoi(inputDayStr));
    /* Allocating Date*/
    OCIDateSetDate ( &boundDateVal, inputYear, inputMonth, inputDay );
    OCIDateSetTime( &boundDateVal, 0, 0, 0);
    returnVal = OCIBindByPos(invalidStmt, &firstInputBindHPtr, myErrorHandle, (ub4) 1,
    (dvoid *) &boundDateVal, (sword) sizeof(boundDateVal),
    SQLT_ODT, /*dty OCIDate*/
    (dvoid *) 0, (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);
    if ( !(returnVal == OCI_SUCCESS || returnVal == OCI_SUCCESS_WITH_INFO) )
    displayErrors (returnVal, myErrorHandle, "OCIBindByPos-contactDate 1 ");
    cleanup();
    exit(1);
    }//if
    returnVal = OCIBindByPos(invalidStmt, &secInputBindHPtr, myErrorHandle, (ub4) 2,
    //(dvoid *) &InputArguments.contactDate, (sword) sizeof(InputArguments.contactDate),
    (dvoid *) &boundDateVal, (sword) sizeof(boundDateVal),
    SQLT_ODT, /*dty OCIDate*/
    (dvoid *) 0, (ub2 *) 0, (ub2 *) 0, (ub4) 0, (ub4 *) 0, OCI_DEFAULT);
    if ( !(returnVal == OCI_SUCCESS || returnVal == OCI_SUCCESS_WITH_INFO) )
    displayErrors (returnVal, myErrorHandle, "OCIBindByPos-contactDate 2 ");
    cleanup();
    exit(1);
    }//if
    }//main
    ** I have had issues w/ OTN not correctly translating certain characters, so hopefully the above example is readable or you can figure out which characters may be missing.

  • OCIBindDynamic()

    Can i use OCIBindDynamic() to bind INPUT variables ? Sometimes i get "ORA-03113 end-of-file on communication channel" error when i use callbacks for INPUT variables, the problem in callbacks or not ?
    Thanks

    All the data sent in one piece (SQLT_INT, SQLT_FLT, SQLT_DAT, SQLT_STR). Strings are small. The application is app server and have many connections to Oracle Server, each connection have self OCIEnv. When end-of-file appears on one client (after DML operation with callbacks), all other clients have same error on similar DML operations. Reboot server machine helps stop the errors :(

Maybe you are looking for

  • Process.destroy() doesn't work?

    Hey, I'm running Java 1.4 on Win 2k, and when I call process.destroy(), the process isn't killed. Here is my code: class MyRunner{ public static void main (String [] args){     Runtime rt = Runtime.getRuntime();     Process pr = null;     try{      

  • Having difficulty assigning more than one tag to a photo...

    I know that you can click more than one tag to a photo, but if I filter for say photos that have no tag, and then assign a tag to that photo, it then is removed from that filter, because it no longer meets the filter's definition - it now has a tag.

  • Customer VMI

    Hi experts, Can you tell me the total solution about customer VMI? And do you have any process document about customer VMI? Thank you so much.

  • Mac Mail 3.6 - Repair function?

    Team - Hope someone can help.  I am using Mac Mail 3.6 (936) - attempting to download messages from a POP server - it begins and will download 2 maybe 3 messages but wont go any further - the spinner icon next to the mail server keeps spinning, there

  • How to tell file size in Elements 9 for Mac

    I'm new to Mac.  I've used Elements for many years.  When I click on File>open and browse my image icons in the "finder" folder (no, I don't use iPhoto), I can't see file size info.  In Windows, I used to be able to hover my cursor over an image icon