SQL> SELECT DEPTNO,ENAME,SAL
2 FROM EMP ORDER BY DEPTNO;
DEPTNO ENAME SAL
---------- ---------- ----------
10 CLARK 2450
10 KING 5000
10 MILLER 1300
20 JONES 2975
20 FORD 3000
20 ADAMS 1100
20 SMITH 800
20 SCOTT 3000
30 WARD 1250
30 TURNER 1500
30 ALLEN 1600
30 JAMES 950
30 BLAKE 2850
30 MARTIN 1250
已选择14行。
PRO*C代码如下:
#include
#include
EXEC SQL INCLUDE SQLCA;
int main(void)
{
EXEC SQL BEGIN DECLARE SECTION;
char *db="";
char ename[5][50]; //5条记录
double salary[5];
int deptno;
int rows;
int i;
EXEC SQL END DECLARE SECTION;
EXEC SQL CONNECT :db;
printf("Connected oracle as user:%s\n",db);
printf("Please input deptno :\n");
scanf("%d",&deptno);
printf("%d\n",deptno);
EXEC SQL SELECT ENAME,SAL INTO :ename,:salary FROM EMP WHERE deptno=:deptno;
printf("sqlcode=%d,sqlmsg=%s\n",sqlca.sqlcode,sqlca.sqlerrm.sqlerrmc);
rows=sqlca.sqlerrd[2];
for(i=0;i printf("%s,%f\n",ename[i],salary[i]);
EXEC SQL COMMIT WORK RELEASE;
return 0;
}
另存为test.pc
以下是记录数不同的表现行为,定义的数组只能存储5条记录。
/home/cpicsrv/yansp > gcc $ORACLE_HOME/lib/libclntsh.so test.c -o test
test.c:412:2: warning: no newline at end of file
/home/cpicsrv/yansp > ./test
Connected oracle as user:scott/tiger@10.223.18.116/yansp
Please input deptno :
10
10
sqlcode=1403,sqlmsg=ORA-01403: no data found
CLARK ,2450.000000
KING ,5000.000000
MILLER ,1300.000000
/home/cpicsrv/yansp > ./test
Connected oracle as user:scott/tiger@10.223.18.116/yansp
Please input deptno :
20
20
sqlcode=0,sqlmsg=
SMITH ,800.000000
JONES ,2975.000000
SCOTT ,3000.000000
ADAMS ,1100.000000
FORD ,3000.000000
/home/cpicsrv/yansp > ./test
Connected oracle as user:scott/tiger@10.223.18.116/yansp
Please input deptno :
30
30
sqlcode=-2112,sqlmsg=SQL-02112: SELECT..INTO returns too many rows
ALLEN ,1600.000000
WARD ,1250.000000
MARTIN ,1250.000000
BLAKE ,2850.000000
TURNER ,1500.000000
/home/cpicsrv/yansp >
阅读(3758) | 评论(0) | 转发(0) |