当前位置: 技术问答>linux和unix
pro*c 里怎么将select 的返回内容赋值给变量
来源: 互联网 发布时间:2016-07-08
本文导语: pro*c 里怎么将select 的返回内容赋值给变量 EXEC SQL BEGIN DECLARE SECTION; char CALLNO[30]; EXEC SQL END DECLARE SECTION; EXEC SQL SELECT CALLNO INTO :CALLNO FROM out_call; EXEC SQL COMMIT WORK RELEASE; ...
pro*c 里怎么将select 的返回内容赋值给变量
EXEC SQL BEGIN DECLARE SECTION;
char CALLNO[30];
EXEC SQL END DECLARE SECTION;
EXEC SQL SELECT CALLNO INTO :CALLNO FROM out_call;
EXEC SQL COMMIT WORK RELEASE;
printf("CALLNO = %sn intCALLNO = %dn",CALLNO,intCALLNO);
打印结果为空,是为啥?
EXEC SQL BEGIN DECLARE SECTION;
char CALLNO[30];
EXEC SQL END DECLARE SECTION;
EXEC SQL SELECT CALLNO INTO :CALLNO FROM out_call;
EXEC SQL COMMIT WORK RELEASE;
printf("CALLNO = %sn intCALLNO = %dn",CALLNO,intCALLNO);
打印结果为空,是为啥?
|
这个查询是一个结果还是多个结果,如果多个结果请使用游标,如果一个结果这句话没什么问题.
1.输出为一个结果的
exec sql begin declare section;
CS_CHAR id[6];
CS_SMALLINT indic;
CS_CHAR pub_name[41];
exec sql end declare section;
exec sql select pub_id into :id indicator :indic
from titles where title
like "%Stress%";
if (indic == -1)
{
printf("npub_id is null");
}
else
{
exec sql select pub_name into :pub_name
from publishers where pub_id = :id;
printf("nPublisher: %s", pub_name);
}
2输出为多个结果的
EXEC SQL DECLARE C1 CURSOR FOR
SELECT id, name, dept, job, years, salary, comm FROM staff;
EXEC SQL OPEN c1;
while (SQLCODE == 0)
{
EXEC SQL FETCH c1 INTO :id, :name, :dept, :job, :years, :salary, :comm;
if (SQLCODE == 0)
printf("%4d %12s %10d %10s %2d %8d %8d",
id, name, dept, job, years, salary, comm);
}
EXEC SQL CLOSE c1;
1.输出为一个结果的
exec sql begin declare section;
CS_CHAR id[6];
CS_SMALLINT indic;
CS_CHAR pub_name[41];
exec sql end declare section;
exec sql select pub_id into :id indicator :indic
from titles where title
like "%Stress%";
if (indic == -1)
{
printf("npub_id is null");
}
else
{
exec sql select pub_name into :pub_name
from publishers where pub_id = :id;
printf("nPublisher: %s", pub_name);
}
2输出为多个结果的
EXEC SQL DECLARE C1 CURSOR FOR
SELECT id, name, dept, job, years, salary, comm FROM staff;
EXEC SQL OPEN c1;
while (SQLCODE == 0)
{
EXEC SQL FETCH c1 INTO :id, :name, :dept, :job, :years, :salary, :comm;
if (SQLCODE == 0)
printf("%4d %12s %10d %10s %2d %8d %8d",
id, name, dept, job, years, salary, comm);
}
EXEC SQL CLOSE c1;
|
EXEC SQL BEGIN DECLARE SECTION;
char CALLNO[30] = "";
EXEC SQL END DECLARE SECTION;
EXEC SQL SELECT CALLNO INTO :CALLNO FROM out_call;
/*EXEC SQL COMMIT WORK RELEASE; 注释此行 */
printf("Count;[%d]",SQL_DISPOSE_ROW_NUM);//增加此行看看结果
printf("CALLNO = %sn intCALLNO = %dn",CALLNO,intCALLNO);
这一段
char CALLNO[30] = "";
EXEC SQL END DECLARE SECTION;
EXEC SQL SELECT CALLNO INTO :CALLNO FROM out_call;
/*EXEC SQL COMMIT WORK RELEASE; 注释此行 */
printf("Count;[%d]",SQL_DISPOSE_ROW_NUM);//增加此行看看结果
printf("CALLNO = %sn intCALLNO = %dn",CALLNO,intCALLNO);
这一段
您可能感兴趣的文章:
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。