Sunday, 26 January 2014

Datatypes in Pro*C/C++


There are  two types of datatypes in pro *c/c++. They are
1.      Internal Datatype
2.      External datatype

Internal Datatype:

Long datatype was not used now. They are depreciated. It belongs to the char family. We can use the long datatyoe if we have backward compatability.
It is now replaced by LOB.

varchar2 & varchar:
varchar is reserved by oracle for future use. ANSI says that “NULL” and empty string are two different things. So if you rely on that use Varchar if not use VARCHAR2.

size of the varchar can be represented in two forms.
1.      memory size
2.      Number of char

Always rely on number of char because we cannot be sure that how many bytes the single character will take. It depend upon the area we use.

Varchar is defined as structure by the precompiler.
Varchar contains the two members  such as arr and len. arr member contains the value where as len contains the len of the arr. while fetching the database the two fields will be updated. But while giving as input to database, it is the responsibility of the programmer to fill those members.

Typically, the arr is  filled with strncpy statement.

char username=”vino_db”;
Varchar user_DB[10];

strncpy((char *)user_DB.arr,username,user_DB.len);

Don’t fail to give the declaration of VARCHAR under the declare section. The size to be mentioned while declaring the varchar.


It is an alias for an real or double precision datatype. Real in precision is 23 or less. Whereas Double is 24 or greater.

There are two types of variables in pro *C/C++.
1.      Host variable
2.      Indicator Variable

Both the Host and Indicator variable will prefix with the semicolon to differentiate with the normal variable. We can also use the struct as host variable by prefixing the struct with the semicolon.

Host Variable:
The host variable is used for communicating between the oracle Database and proc language. For eg if we want to retrieve the data from the database and use that data in programming we can use the host variable.

EXEC SQL select  AGE into :age_HV  :age_IV  from PROFILE where  EMP_ID = :EMPID_HV;
In this statement age_HV is the host variable. After successful execution of select statement, age of the given employee will be copied to age_HV.

Indicator variable:
The indicator variable is one which states the condition of the  host variable. It is the short integer.

EXEC SQL select  AGE into :age_HV  :age_IV  from PROFILE where  EMP_ID = :EMPID_HV;
In this statement age_IV is the indicator variable. If this variable  is assigned as 0 after executing the select statement then it indicates that age is copied to host variable age_HV. If it is -1 , then it indicates that value is not fetched. That’s why it is called as indicator variable.

Host array:
It is used to handle the multiple data at a stretch.