The below code will connect to oracle database and fetch the records from particular table and same will be written in external file.
#include#include #include #include EXEC SQL INCLUDE SQLCA; EXEC SQL BEGIN DECLARE SECTION; static char Column_Var[33]=""; char vPswdStr[50]="username/password@dbname"; char dot[5]; EXEC SQL END DECLARE SECTION; FILE *fa=NULL; main() { fa=fopen("man.dat","a+"); EXEC SQL CONNECT :vPswdStr; strcpy(dot,"."); printf("Dot=%s",dot); EXEC SQL DECLARE c1 CURSOR FOR SELECT column_name FROM TableName; EXEC SQL OPEN c1; EXEC SQL WHENEVER NOT FOUND DO break; while(1) { EXEC SQL FETCH c1 INTO :Column_Var ; fprintf(fa," NAME=[%s]\n",Column_Var); } }
Steps to compile and run the above code
1.First copy above code and save it as filename.pc2.proc -name=filename.pc
then it will generate filename.c file
3.compile *.c file file using gcc command and then it will generate *.o file and run the program as normal C code.
No comments:
Post a Comment