Getting Started Oracle Pro*C

19 Dec

We will start oracle pro*C with basic examples and end up with pro*C Advanced Examples: (I will add examples day to day, you have to check it by clicking the next pages to this page and then further)

Example : Select records from a database
You have to create a table named employee as :
SQL> create table employee (empno number(5), empname varchar2(50), deptno number(2)) ;
also insert some data in it.
I have a user named ddo with password ddo you should use your user information in this example where I have used my user ddo.

#include
#include

void sqlerror();

EXEC SQL BEGIN DECLARE SECTION;
char *connstr = “ddo/ddo”;
char v_empname[50];
int v_deptno;
EXEC SQL END DECLARE SECTION;
void main() {
EXEC SQL WHENEVER SQLERROR DO sqlerror();
EXEC SQL WHENEVER SQLWARNING CONTINUE;
EXEC SQL CONNECT :connstr;
EXEC SQL WHENEVER NOTFOUND GOTO notfound;
EXEC SQL SELECT empname, deptno
INTO v_empname, v_deptno
FROM employee
WHERE empno = 21114;

found:
printf(“%s is in department %i\n”, v_empname, v_deptno);
return;

notfound:
printf(“Employee record not found in database.\n”);
return;

}

void sqlerror() {
printf(“Stop Error:\t%25i\n”, sqlca.sqlcode);
return;

}

source : internet

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: