I recently learned how to use proc for Oracle application development. However, I did not have much detail about this on the Internet. After some twists and turns, I finally completed a test case.
The function implemented by the program is very simple. By accessing a remote ORACLE database, a field is read, returned, and displayed. As I am a beginner and have limited capabilities, I hope I can help you with some beginners.
Preparations: Install the Oracle client, set the corresponding environment variables, and configure TNS ($ ORACLE_HOME/Network/admin/tnsnames. ora)
Main steps: Use proc to compile a. PC file -----> Use proc to pre-compile ----> Generate a. c file ------> Generate an executable file for CC/GCC Compilation
The specific file content is as follows:
Conn. PC File
# Include <stdio. h> # include <stdlib. h> exec SQL begin declare section; char userid [20] = "***/***"; /* username/password */Char remotedb [20] = "***";/* servername In the TNS corresponding to the remote database, see TNS configuration */Char data [2]; exec SQL end declare section; Exec SQL include sqlca; void sqlerror (); int main () {exec SQL whenever sqlerror do sqlerror (); Exec SQL CONNECT: userid using: remotedb; exec SQL select test into: Data from temp where serial_num BER = '1'; Exec SQL commit work release; printf ("datebase data: \ t % s \ n", data); exit (0);} void sqlerror () {exec SQL whenever sqlerror continue; Exec SQL rollback work release; printf ("----- Pro * C connect error! ---- N "); exit (-1 );}
Below is the MAKEFILE file, which was found online. It was simply modified and I would like to thank you first.
ORACLE_HOME=/oracle/product/10.2/db_1INCLDIR= -I. -I$ORACLE_HOME/precomp/public -I$ORACLE_HOME/rdbms/public -I$ORACLE_HOME/rdbms/demo -I$ORACLE_HOME/plsql/public -I$ORACLE_HOME/network/public DFLAGS= -DPRECOMP -DLINUX -D_GNU_SOURCE -DSLTS_ENABLE -DSLMXMX_ENABLE -D_REENTRANT -DNS_THREADSCFLAGS= -O3LIBPATH= -L$ORACLE_HOME/lib/LIBS=-lclntsh -ldl -lmconn:conn.pc proc parse=no iname=conn.pc include=$(ORACLE_HOME)/precomp/public cc -o $@ $@.c -I$(ORACLE_HOME)/precomp/public -L$(ORACLE_HOME)/lib -lclntsh -lclient10 $(LIBPATH) $(LIBS)clean: rm *.lis conn.c conn
Execute make
Generate the corresponding. c file and executable file Conn
Run./Conn
Display
Datebase data: 5