Results 1 to 2 of 2
  1. #1
    Join Date
    Dec 2003
    Posts
    1

    Question Unanswered: Dynamic SQL and PROC/C++ issue

    Hi folks!

    I am a novice in PROC/C++ so I think that this question is quite easy for a pro. Usually when I write code I prefer to create functions that has as few hardcoded statements as possible. So I think I will like dynamic SQL but right now I encountered a problem.

    I want to write a function that takes 2 arguments, name of the table and a NET8 name. This function shall return the number of rows in that table.

    My attempt below does not work:

    unsigned int db_count(char *table_name, char *server_id)
    {
    EXEC SQL BEGIN DECLARE SECTION;
    unsigned int cnt = 10;
    char sqlstmt[MAX_SQLSTMT_LENGTH];
    EXEC SQL END DECLARE SECTION;

    sprintf(sqlstmt, "SELECT COUNT(*)INTO :cnt FROM %s", table_name);

    EXEC SQL WHENEVER SQLERROR DO return(sql_error(server_id, "Error counting rows in table %s.", table_name));
    EXEC SQL AT :server_id EXECUTE IMMEDIATE :sqlstmt;

    return(cnt);
    }

    I tried several ways and tries to read the Oracle documents but I do net get any wiser. Can someone please guide me or at list give me a tip.

    Best Regards
    /Fredrik

  2. #2
    Join Date
    Oct 2003
    Posts
    2
    Hello,

    There a sql method 3 in Pro*c read about it it will fullfill your requirement.


    Regards
    Bhagat Singh

Posting Permissions

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