Skip to content Skip to sidebar Skip to footer

Check For Zero Rows In Select Query

My C program has an embedded sql query. This program runs on windows and queries the oracle database. The query is similar to EXEC SQL SELECT ... I need to add here a check to know

Solution 1:

Use the sqlca struct

EXECSQL include "sqlca.h"
#define NO_ROWS_FOUND (sqlca.sqlcode==1403)
EXECSQLBEGINDECLARE SECTION;
    int val=0;
    short ind=0;
EXECSQLENDDECLARE SECTION;

EXECSQLselectvalueint :val :ind 
      from mytable where rownum=1;
if(NO_ROWS_FOUND)
   printf("No rows found\n");

Solution 2:

Use SELECT COUNT(*) FROM ... and compare result to 0.

Post a Comment for "Check For Zero Rows In Select Query"