今天就跟大家聊聊有关Pro*C中怎样嵌入pl/sql块,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
EXEC SQL INCLUDE sqlca;
EXEC SQL INCLUDE sqlda;
int main()
{
EXEC SQL BEGIN DECLARE SECTION;
int money;
char answerbuff[200];
int flag;
char username[10],password[10],server[10];
EXEC SQL END DECLARE SECTION;
strcpy(username,"data_center");
strcpy(password,"data_center");
strcpy(server,"oradf1");
EXEC SQL CONNECT :username IDENTIFIED BY :password USING :server;
if (sqlca.sqlcode==0)
printf("连接成功!/n");
else
printf("%.*s/n", sqlca.sqlerrm.sqlerrml,
sqlca.sqlerrm.sqlerrmc);
money=0;
flag=0;
EXEC SQL EXECUTE
BEGIN
SELECT salary INTO :money FROM plsqltest WHERE name='ht';
:flag:=1;
EXCEPTION
WHEN NO_DATA_FOUND THEN
:answerbuff:='数据没有找到';
END;
END-EXEC;
if (flag==0)
printf("%s/n",answerbuff);
else
printf("总工资是:%d/n",money);
}
=================================================
编译方法:
1. 如果在PC源程序中内嵌了PL/SQL块, SQLCHECK应该SEMANTICS或是 FULL
2. 当SQLCHECK的值是SEMANTICS或是 FULL时,必须设置USERID
proc PARSE=NONE include=-I/opt/oracle/product/10.2.0/precomp/public include=-I/opt/oracle/product/10.2.0/rdbms/public sqlcheck=fullUSERID=data_center/data_center@oradf1 iname=test.pc oname=test.c
gcc的一些选项,不加这些,有时会报错。
gcc -L/opt/oracle/product/10.2.0/lib -lclntsh -ldl -lm -lnsl -o test test.c
===========================================
创建表:
create table PLSQLTEST
(
salary NUMBER,
NAME VARCHAR2(10)
);
insert into plsqltest (salary, NAME)
values (1000, 'xym');
insert into plsqltest (salary, NAME)
values (2000, 'ht');
commit;
看完上述内容,你们对Pro*C中怎样嵌入pl/sql块有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。