Chinaunix首页 | 论坛 | 博客
  • 博客访问: 2886878
  • 博文数量: 599
  • 博客积分: 16398
  • 博客等级: 上将
  • 技术积分: 6875
  • 用 户 组: 普通用户
  • 注册时间: 2009-11-30 12:04
个人简介

WINDOWS下的程序员出身,偶尔也写一些linux平台下小程序, 后转行数据库行业,专注于ORACLE和DB2的运维和优化。 同时也是ios移动开发者。欢迎志同道合的朋友一起研究技术。 数据库技术交流群:58308065,23618606

文章分类

全部博文(599)

文章存档

2014年(12)

2013年(56)

2012年(199)

2011年(105)

2010年(128)

2009年(99)

分类: Oracle

2012-01-04 17:26:21


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) |
给主人留下些什么吧!~~