Thursday, January 20, 2011

Stored ProC: Select Statement

//Select statement: 
varchar2 in_id[20];

int Poster::sendWLReq(char *arg_access_code, char *out_msg)
{
        char tmp_id[160];
      
        strncpy( tmp_id, arg_access_code, sizeof(tmp_id) - 1);
        tmp_id[sizeof(tmp_id) - 1] = '\0';

        EXEC SQL WHENEVER NOTFOUND goto notFound;

        memset((char*)in_id.arr, NULL, 15);
        strcpy((char*)in_id.arr, tmp_id);
        in_id.len=strlen(tmp_id);
        in_id.arr[in_id.len]='\0';

        cout << "arg_brand->" << (char*)in_id.arr << "<-arg_brand" << endl;

        EXEC SQL AT DB_NAME
                select STAFF into :out_msg_cont
                from STAFF_LIST
                where MSISDN = :in_id;

        cout << "sql error code " << sqlca.sqlcode << "   " << sqlca.sqlerrm.sqlerrmc << endl;

        strcpy(out_msg, (char*)out_msg_cont.arr);
      
        return 0;

        notFound:
        EXEC SQL WHENEVER NOTFOUND  CONTINUE;

        return 1;
}

This C function can be extended to any other oracle statement.

No comments:

Post a Comment