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;
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;
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.