免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
12345下一页
最近访问板块 发新帖
查看: 9871 | 回复: 45
打印 上一主题 下一主题

[C] pro*c中如何定义一个枚举变量? [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2009-06-25 10:46 |只看该作者 |倒序浏览
20可用积分
==========================
大家帮我看看这个问题啊,顿首谢!
我的所有代码都在这里,究竟是什么错呢?
哪位高手朋友路过,求您指点迷津!


感谢"gawk"
==========================
我的pro*c文件:
-------------------------
[oracle@oracle11gTux1 lessons]$ cat ./gg.pc

#define USERNAME "pw"
#define PASSWORD "pw"
#define SERVICE "wilson"
#include <stdio.h>
#include <stdlib.h>
#include "sqlca.h"

EXEC SQL INCLUDE SQLCA;

typedef char ascie[20];
EXEC SQL BEGIN DECLARE SECTION;
        char *username=USERNAME;
        char *passwd=PASSWORD;
        char *service=SERVICE;

        ascie name;
        int age;
        float salary;
EXEC SQL END DECLARE SECTION;

void sqlerr()
{
        EXEC SQL WHENEVER SQLERROR CONTINUE;
        printf("\n%.*s\n",sqlca.sqlerrm.sqlerrml,sqlca.sqlerrm.sqlerrmc);
        EXEC SQL ROLLBACK WORK RELEASE;
        exit(1);
}
int main()
{
        EXEC SQL WHENEVER SQLERROR DO sqlerr();

        EXEC SQL CONNECT :username IDENTIFIED BY :passwd USING :service;

        EXEC SQL DECLARE emp_cursor CURSOR FOR
                SELECT NAME,AGE,SALARY FROM EMP;
        EXEC SQL OPEN emp_cursor;

        while(true)
        {
                EXEC SQL WHENEVER NOT FOUND DO break;
                EXEC SQL FETCH emp_cursor
                        INTO :name, :age, :salary;

                printf("\n%s",sqlca.sqlerrd[2]);
                printf("\n%.*s\n",name,age,salary);
        }
        EXEC SQL CLOSE emp_cursor;
        EXEC SQL COMMIT WORK RELEASE;

        //if (sqlca.sqlcode == 0)
        //      printf("\n Connected!\n");
        //else
        //      printf("\n%.*s\n",sqlca.sqlerrm.sqlerrml,sqlca.sqlerrm.sqlerrmc);

        return 0;
}
[oracle@oracle11gTux1 lessons]$
以上标红色部分应该怎么写?
-------------------------------------------报的错误:
[oracle@oracle11gTux1 lessons]$ proc ./gg.pc

Pro*C/C++: Release 11.1.0.6.0 - Production on Thu Jun 25 05:15:15 2009

Copyright (c) 1982, 2007, Oracle.  All rights reserved.

System default option values taken from: /u01/oracle/precomp/admin/pcscfg.cfg

Syntax error at line 17, column 2, file ./gg.pc:
Error at line 17, column 2 in file ./gg.pc
        ascie name;
.1
PCC-S-02201, Encountered the symbol "ascie" when expecting one of the following:

   auto, char, const, double, enum, extern, float, int, long,
   ulong_varchar, OCIBFileLocator OCIBlobLocator,
   OCIClobLocator, OCIDateTime, OCIExtProcContext, OCIInterval,
   OCIRowid, OCIDate, OCINumber, OCIRaw, OCIString, register,
   short, signed, sql_context, sql_cursor, static, struct,
   typedef, union, unsigned, utext, uvarchar, varchar, void,
   volatile, a typedef name, a precompiled header, exec oracle,
   exec oracle begin, exec, exec sql, exec sql begin,
   exec sql end, exec sql type, exec sql var, exec sql include,
The symbol "enum," was substituted for "ascie" to continue.

Error at line 0, column 0 in file ./gg.pc
PCC-F-02102, Fatal error while doing C preprocessing

[oracle@oracle11gTux1 lessons]$

[ 本帖最后由 simhare 于 2009-6-25 17:51 编辑 ]

最佳答案

查看完整内容

嗯,我看了oracle中的例子是这样弄的,我自己proc 执行了一下能通过你自己在编译一下看看运行怎么样

论坛徽章:
0
2 [报告]
发表于 2009-06-25 10:46 |只看该作者
原帖由 simhare 于 2009-6-25 17:28 发表
好吧,我试试
===========
ascie name;
换成:
char name[20];
============
是这样吗?

嗯,我看了oracle中的例子是这样弄的,我自己proc 执行了一下能通过
你自己在编译一下看看运行怎么样

论坛徽章:
0
3 [报告]
发表于 2009-06-25 10:48 |只看该作者

回复 #1 simhare 的帖子

Syntax error at line 17, column 2, file ./gg.pc:
Error at line 17, column 2 in file ./gg.pc
        ascie name;
.1
PCC-S-02201, Encountered the symbol "ascie" when expecting one of the following:

   auto, char, const, double, enum, extern, float, int, long,
   ulong_varchar, OCIBFileLocator OCIBlobLocator,
   OCIClobLocator, OCIDateTime, OCIExtProcContext, OCIInterval,
   OCIRowid, OCIDate, OCINumber, OCIRaw, OCIString, register,
   short, signed, sql_context, sql_cursor, static, struct,
   typedef, union, unsigned, utext, uvarchar, varchar, void,
   volatile, a typedef name, a precompiled header, exec oracle,
   exec oracle begin, exec, exec sql, exec sql begin,
   exec sql end, exec sql type, exec sql var, exec sql include,
The symbol "enum," was substituted for "ascie" to continue.


Error at line 0, column 0 in file ./gg.pc
PCC-F-02102, Fatal error while doing C preprocessing
------------------------------
报的这个错误是什么意思?

论坛徽章:
0
4 [报告]
发表于 2009-06-25 10:51 |只看该作者

回复 #1 simhare 的帖子

mgqw 离线了,谁来帮我?

[ 本帖最后由 simhare 于 2009-6-25 10:54 编辑 ]

论坛徽章:
0
5 [报告]
发表于 2009-06-25 10:52 |只看该作者
跟其他C代码定义枚举有区别么?

论坛徽章:
0
6 [报告]
发表于 2009-06-25 10:53 |只看该作者

回复 #1 simhare 的帖子

我的分数最好赚,谁帮我解决了问题,立刻给分数,2009.6.24----12点钟会下线.
------------------------

论坛徽章:
0
7 [报告]
发表于 2009-06-25 10:58 |只看该作者

回复 #4 net_robber 的帖子

我不知道啊,我都快10年没接触C了,早就忘了.
------------
你帮我看看上面这段pro*c的代码有什么问题,好吗?

论坛徽章:
0
8 [报告]
发表于 2009-06-25 10:59 |只看该作者

回复 #1 simhare 的帖子

还有哪位路过的高手也帮我看看啊......
-----------------
谢谢!
-----------------

论坛徽章:
0
9 [报告]
发表于 2009-06-25 11:01 |只看该作者
枚举直接定义就是了,搞那么多划花肠子干吗?
enum ascie{ a, b, c, d, e }

论坛徽章:
0
10 [报告]
发表于 2009-06-25 11:04 |只看该作者

回复 #8 mgqw 的帖子

typedef char ascie[20] enum;
EXEC SQL BEGIN DECLARE SECTION;
        char *username=USERNAME;
        char *passwd=PASSWORD;
        char *service=SERVICE;

       ascie name;-------那这里怎么办?
        int age;
        float salary;
EXEC SQL END DECLARE SECTION;

[ 本帖最后由 simhare 于 2009-6-25 11:05 编辑 ]
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP