How to compile and run Pro*C Sample Program
- The following are the steps required to make and run the program:
- First, we'd like to put in the Oracle database, and Microsoft Visual C++. In Visual C++, we'll create our C program that contains the embedded SQL statements.
- This program will connect with a oracle database.
- The oracle database contains the in-built PROC components. To see whether the PROC has been installed successfully, open the cmd and type the 'proc' command.

Command Prompt
- After entering the proc command in prompt , we press enter:

Installation
- The above screen shows that the proc has been installed successfully.
- Now, we'll create a C program in Visual C++. Open Visual C++. once we open the Visual C++, the image shown below will appear:

Visual c++
- Click on the File appearing at the top menu. Move the mouse over the New, then click on the Project.

Start Page in Visual c++
- When we click on the project, the screen appears shown below:

Empty Project
- In the above screen, click on the overall appearing at the left-side under the Visual C++ category, then click on the Empty Project. Now, we'd like to provide the name to the present empty project.

Empty Project
- In the above screen, click on the overall appearing at the left-side under the Visual C++ category, then click on the Empty Project. Now, we'd like to supply the name to the present empty project.

Demo
- In the above screen, we will see that the workspace of our project has been created. At the leftmost side, we will see the hierarchy of our project which contains External Dependencies, Header Files, Resource files, and Source files.
- Now, we've to feature the library files of Oracle, so right-click on the header files, then keep the mouse cursor over the Add then click on the Existing-item.

Add Existing Item
- Move to the oracle folder which contains precomp as a subdirectory. Click on the precomp.

Precomp Folder
- When we click on the precomp folder, the screen shown below will appear:

Lib Folder
- Click on the lib folder, which is shown within the above screen.
- Now add the 2 object library files, i.e., orasql19, and another one is orasqx19, which is present within the msvc folder.

Orasql19

Orasqx19
- When we add the above two library files, our Solution Explorer window would look like:

Solution Explorer
- In the above screen, the highlighted area shows that both the library files are added successfully in our project.
- Now, we add ASCII text file in our project. To do so, right-click on the source files, keep the mouse cursor over the Add then click on the New item.
Read Also

Add New Item
- After clicking on the New item, the screen appears as shown below:

c++ file
- In the above screen, click on the Code that appears at the leftmost side, then click on the C++ File. We even have provided the file name as first with a .pc extension.
- After providing the name to the source file, we click on the Add button.

Add Button
- In the above screen, we will observe that the workspace for the file that we've added has been created.
- The following is that the code of pc file:
execsql begin declare section;
charuser_name[20],password[20];
execsql end declare section;
execsql include sqlca;
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
printf("Enter the user name");
scanf("%s",user_name);
printf("Enter the password");
scanf("%s",password);
execsql connect :user_name identified by :password;
if(sqlca.sqlcode==0)
printf("Success");
else
printf("Error code:%d\n Error message:%s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
getch();
}
- Open the cmd, and move thereto folder, i.e., E:\Demo\Demo where first.pc file is stored.

Move Thereto Folder
- Now, we use the proc compiler to precompile the first.pc program as shown within the below screenshot:

proc first

first
- In the above screen, we will observe that first.c has been created after compilation of first.pc by Oracle precompiler.
- Now, we add the primary .c enter Visual C++. to feature this file, right-click on the Source files, then keep the mouse cursor on Add then click on the prevailing item. The below screen shows that first.c file has been added in Visual C++.

Source File
- After the compilation of first.pc, the code of first.c would be:
Read Also
/* Result Sets Interface */
#ifndef SQL_CRSR
# define SQL_CRSR
structsql_cursor
{
unsignedintcurocn;
void *ptr1;
void *ptr2;
unsignedint magic;
};
typedefstructsql_cursorsql_cursor;
typedefstructsql_cursor SQL_CURSOR;
#endif /* SQL_CRSR */
/* Thread Safety */
typedef void * sql_context;
typedef void * SQL_CONTEXT;
/* Object support */
structsqltvn
{
unsigned char *tvnvsn;
unsigned short tvnvsnl;
unsigned char *tvnnm;
unsigned short tvnnml;
unsigned char *tvnsnm;
unsigned short tvnsnml;
};
typedefstructsqltvnsqltvn;
structsqladts
{
unsignedintadtvsn;
unsigned short adtmode;
unsigned short adtnum;
sqltvnadttvn[1];
};
typedefstructsqladtssqladts;
staticstructsqladtssqladt = {
1,1,0,
};
/* Binding to PL/SQL Records */
structsqltdss
{
unsignedinttdsvsn;
unsigned short tdsnum;
unsigned char *tdsval[1];
};
typedefstructsqltdsssqltdss;
staticstructsqltdsssqltds =
{
1,
0,
};
/* File name & Package Name */
structsqlcxp
{
unsigned short fillen;
charfilnam[9];
};
staticconststructsqlcxpsqlfpn =
{
8,
"first.pc"
};
static unsigned intsqlctx = 18667;
staticstructsqlexd {
unsignedintsqlvsn;
unsignedintarrsiz;
unsignedintiters;
unsignedint offset;
unsigned short selerr;
unsigned short sqlety;
unsignedint occurs;
const short *cud;
unsigned char *sqlest;
const char *stmt;
sqladts *sqladtp;
sqltdss *sqltdsp;
void **sqphsv;
unsignedint *sqphsl;
int *sqphss;
void **sqpind;
int *sqpins;
unsignedint *sqparm;
unsignedint **sqparc;
unsigned short *sqpadto;
unsigned short *sqptdso;
unsignedintsqlcmax;
unsignedintsqlcmin;
unsignedintsqlcincr;
unsignedintsqlctimeout;
unsignedintsqlcnowait;
intsqfoff;
unsignedintsqcmod;
unsignedintsqfmod;
void *sqhstv[4];
unsignedintsqhstl[4];
intsqhsts[4];
void *sqindv[4];
intsqinds[4];
unsignedintsqharm[4];
unsignedint *sqharc[4];
unsigned short sqadto[4];
unsigned short sqtdso[4];
} sqlstm = {12,4};
/* SQLLIB Prototypes */
extern void sqlcxt (void **, unsigned int *,
structsqlexd *, conststructsqlcxp *);
extern void sqlcx2t(void **, unsigned int *,
structsqlexd *, conststructsqlcxp *);
extern void sqlbuft(void **, char *);
extern void sqlgs2t(void **, char *);
extern void sqlorat(void **, unsigned int *, void *);
/* Forms Interface */
staticconstint IAPSUCC = 0;
staticconstint IAPFAIL = 1403;
staticconstint IAPFTL = 535;
extern void sqliem(unsigned char *, signed int *);
typedefstruct { unsigned short len; unsigned char arr[1]; } VARCHAR;
typedefstruct { unsigned short len; unsigned char arr[1]; } varchar;
/* cud (compilation unit data) array */
staticconst short sqlcud0[] =
{12,4130,178,0,0,
5,0,0,0,0,0,27,14,0,0,4,4,0,1,0,1,97,0,0,1,97,0,0,1,10,0,0,1,10,0,0,
};
/* exec sql begin declare section; */
charuser_name[20],password[20];
/* exec sql end declare section; */
/* exec sql include sqlca;
*/
#ifndef SQLCA
#define SQLCA 1
structsqlca
{
/* ub1 */ char sqlcaid[8];
/* b4 */ intsqlabc;
/* b4 */ intsqlcode;
struct
{
/* ub2 */ unsigned short sqlerrml;
/* ub1 */ char
sqlerrmc[70];
} sqlerrm;
/* ub1 */ char sqlerrp[8];
/* b4 */ int
sqlerrd[6];
/* ub1 */ char sqlwarn[8];
/* ub1 */ char sqlext[8];
};
#ifndef SQLCA_NONE
#ifdef
SQLCA_STORAGE_CLASS
SQLCA_STORAGE_CLASS structsqlcasqlca
#else
structsqlcasqlca
#endif
#ifdef SQLCA_INIT
= {
{'S', 'Q', 'L', 'C', 'A', ' ', ' ', ' '},
sizeof(structsqlca),
0,
{ 0, {0}},
{'N', 'O', 'T', ' ', 'S', 'E', 'T', ' '},
{0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}
}
#endif
;
#endif
#endif
/* end SQLCA */
#include<stdio.h>
#include<conio.h>
#include<stdlib.h>
void main()
{
printf("Enter the user name");
scanf("%s",user_name);
printf("Enter the password");
scanf("%s",password);
/* exec sqlconnect :user_name identified by :password; */
{
structsqlexdsqlstm;
sqlstm.sqlvsn = 12;
sqlstm.arrsiz = 4;
sqlstm.sqladtp = &sqladt;
sqlstm.sqltdsp = &sqltds;
sqlstm.iters = (unsigned int )10;
sqlstm.offset = (unsigned int )5;
sqlstm.cud = sqlcud0;
sqlstm.sqlest = (unsigned char *)&sqlca;
sqlstm.sqlety = (unsigned short)4352;
sqlstm.occurs = (unsigned int )0;
sqlstm.sqhstv[0] = ( void *)user_name;
sqlstm.sqhstl[0] = (unsigned int )20;
sqlstm.sqhsts[0] = ( int )20;
sqlstm.sqindv[0] = ( void *)0;
sqlstm.sqinds[0] = ( int )0;
sqlstm.sqharm[0] = (unsigned int )0;
sqlstm.sqadto[0] = (unsigned short )0;
sqlstm.sqtdso[0] = (unsigned short )0;
sqlstm.sqhstv[1] = ( void *)password;
sqlstm.sqhstl[1] = (unsigned int )20;
sqlstm.sqhsts[1] = ( int )20;
sqlstm.sqindv[1] = ( void *)0;
sqlstm.sqinds[1] = ( int )0;
sqlstm.sqharm[1] = (unsigned int )0;
sqlstm.sqadto[1] = (unsigned short )0;
sqlstm.sqtdso[1] = (unsigned short )0;
sqlstm.sqphsv = sqlstm.sqhstv;
sqlstm.sqphsl = sqlstm.sqhstl;
sqlstm.sqphss = sqlstm.sqhsts;
sqlstm.sqpind = sqlstm.sqindv;
sqlstm.sqpins = sqlstm.sqinds;
sqlstm.sqparm = sqlstm.sqharm;
sqlstm.sqparc = sqlstm.sqharc;
sqlstm.sqpadto = sqlstm.sqadto;
sqlstm.sqptdso = sqlstm.sqtdso;
sqlstm.sqlcmax = (unsigned int )100;
sqlstm.sqlcmin = (unsigned int )2;
sqlstm.sqlcincr = (unsigned int )1;
sqlstm.sqlctimeout = (unsigned int )0;
sqlstm.sqlcnowait = (unsigned int )0;
sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn);
}
if(sqlca.sqlcode==0)
printf("Success");
else
printf("Error code:%d\n Error message:%s",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
getch();
}
Run
- We can run our program by simply clicking on the Debug that appears at the top menu, then click on the start Debugging.

Run The Program