用proc命令时出现缺少包libclntsh.so,解决办法,在/etc/profile里加入
LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/u01/app/oracle/product/10.2.0/db_1/lib:/u01/app/oracle/product/10.2.0/db_1/precomp/lib
然后gcc用proc生成的c文件时,undefined reference to 'sqlcxt' ,’sqlglm‘。
因为gcc不知道lib包的位置。用命令
gcc main.c -L. -L/u01/app/oracle/product/10.2.0/db_1/lib/ -lDblink -lclntsh -o main
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <fcntl.h>
#include <string.h>
#include <math.h>
#include <sys/types.h>
EXEC SQL include sqlca;
int main(int argc,char *argv[])
{
EXEC SQL BEGIN DECLARE SECTION;
int number,num;
VARCHAR mytmp[20];
EXEC SQL END DECLARE SECTION;
int iret;
num = 12;
number = 0;
iret = db_connect();
EXEC SQL DECLARE mycursor CURSOR FOR
select it,mt from mytab;
EXEC SQL OPEN mycursor;
for(;;)
{
EXEC SQL WHENEVER NOT FOUND DO break;
EXEC SQL FETCH mycursor into :number,:mytmp;
printf("%d--%.*s/n", number, mytmp.len, mytmp.arr);
}
EXEC SQL CLOSE mycursor;
//下面这句话,是为了把上面的do break给去掉.
EXEC SQL WHENEVER NOT FOUND CONTINUE;
EXEC SQL select it,mt into :number,:mytmp from mytab where it=:num;
printf("%d--%d--%.*s/n", sqlca.sqlcode, number, mytmp.len, mytmp.arr);
db_disconnect();
return 0;
}