proc Programming Embedded Sql:sql writing to a C language Program proc programming header file path app\xxx\product\11.2.0\dbhome_1\precomp\ Publicproc Programming Note that the proc compiler will also use the header file in the GCC compiler, so you need to configure it in the proc compiler, plus the system header file path profile path is: app\xxx\product\11.2.0\dbhome_1\precomp\admin\pcscfg.cfgproc Development Process1. Proc Tool Precompiled *.pc==>. Cproc compilation options: Parse=full|none (defaultFull forC,others forC + +) code=ansi_c| CPP (defaultAnsi_c) C language compilation: proc source file generation file C+ + Compile: Proc source file generation file Parse=none code=CPP2. Linux under Compile Gcc-o dm01_hello dm01_hello.c-i/home/oracle_11/app/oracle/product/11.2.0/db_1/precomp/ Public -l/home/oracle_11/app/oracle/product/11.2.0/db_1/lib-Lclntsh--Linux View Oracle error code: Oerr ora error code3. Execute application proc Program structure include header file (c/c++ and Pro*c/c++define a variable definition function main connection database: Connect SQL ACTION statement: EXEC SQL ... Handling exception: Exception handler disconnect: EXEC SQL COMMIT. ROLLBACK Work Release
#include <stdio.h>#include<stdlib.h>#include<string.h>#include"sqlca.h"//Define the host variable (SQL variable) firstEXEC SQL BEGIN DECLARE section; Char* serverid="scott/123456"; EXEC SQL END DECLARE section;voidMain () {intret=0; //using host variables in the C languageprintf"serverid=%s\r\n", ServerID); //connecting to a databaseEXEC SQL Connect:serverid; if(sqlca.sqlcode!=0) {ret=Sqlca.sqlcode; printf ("Connect err:%d", ret); System ("Pause"); } printf ("Connect ok!\r\n"); //COMMIT Transaction DisconnectEXEC SQL commit release; printf ("Oracle closed!\r\n"); System ("Pause");}
Database proc Programming One