免费注册 查看新帖 |

Chinaunix

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

Linux C调用DB2存储过程 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-11-26 13:43 |只看该作者 |倒序浏览
exec sql begin declare section;
        char procname[254] = "batch_storage";
        char stmt[256];
        sqlint16 int_code;
        char str_date[8];
        char str_merchant[16];
        sqlint16  start_id;
        sqlint16  end_id;
exec sql end declare section;

int batch_storage(char  *merchant_no,int start_no,int end_no,char *start_date,int code)
{

        char sqlstate[256];
        struct sqlda *inout_sqlda = (struct sqlda *)
        malloc(SQLDASIZE(1));
        struct sqlca sqlca;
        memset(str_date,0,sizeof(str_date));
        memset(str_merchant,0,sizeof(str_merchant));
        memcpy(str_date,start_date,strlen(start_date));
        memcpy(str_merchant,merchant_no,strlen(merchant_no));
        start_id=start_no;
        end_id=end_no;
        printf("Use CALL with Host Variables to invoke the Server Procedure name=[%s]\n",procname);
        sprintf(stmt, "CALL %s (?,?,?,?,?)", procname);
        EXEC SQL prepare st from :stmt;
        printf("sqlca.sqlcode=[%d]\n",sqlca.sqlcode);
        EXEC SQL execute st into :int_code USING :str_merchant:start_id:end_id:str_date;
        printf("sqlca.sqlcode=[%d]\n",sqlca.sqlcode);
        if(sqlca.sqlcode!=0)
        {
                return(91);
        }
        code=atoi(str_code);
        free( inout_sqlda );
        return 0;



不知道为什么一直报EXEC SQL execute st into :int_code USING :str_merchant:start_id:end_id:str_date;出错
错误信息为:
LINE    MESSAGES FOR leave.sqc
------  --------------------------------------------------------------------
        SQL0060W  The "C" precompiler is in progress.
   39   SQL0104N  An unexpected token ":" was found following ":".  
                  Expected tokens may include:  "END-OF-STATEMENT".
        SQL0095N  No bind file was created because of previous
                  errors.
        SQL0091W  Precompilation or binding was ended with "2"
                  errors and "0" warnings.
make: *** [leave] Error 4


请高手帮我分析一下

论坛徽章:
0
2 [报告]
发表于 2007-11-26 13:44 |只看该作者
存储过程的脚本为:
drop procedure batch_storage @
CREATE PROCEDURE batch_storage(in merchant_no char(15),in start_no int,in end_no int,in start_date char(9),out re_code int)
RESULT SETS 1
LANGUAGE SQL
BEGIN
        DECLARE SQLCODE INTEGER DEFAULT 0;
        declare count int;
        declare mtemp char(15);
        DECLARE EXIT HANDLER FOR SQLEXCEPTION,NOT FOUND
        BEGIN
        set re_code=SQLCODE;
        END;
        set count = start_no;
        select merchant_no into mtemp from merchant where merchant_no=merchant_no;
        while (count <= end_no)
        do
                insert into merchant_logic values(merchant_no,count,'00',start_date,'');
                set count=count+1;
        end while;
        commit;
END @

论坛徽章:
0
3 [报告]
发表于 2007-11-26 13:54 |只看该作者
版主在吗???

论坛徽章:
0
4 [报告]
发表于 2007-11-26 13:56 |只看该作者
请高手帮我看看这个问题

论坛徽章:
0
5 [报告]
发表于 2007-11-28 09:54 |只看该作者
select merchant_no into mtemp from merchant where merchant_no=merchant_no;
你的输入参数有个 merchant_no ,在表 merchant 中有个字段也是 merchant_no ,DB2如何知道!?
参数要规范一些

论坛徽章:
11
数据库技术版块每日发帖之星
日期:2016-06-25 06:20:00数据库技术版块每日发帖之星
日期:2016-06-24 06:20:00数据库技术版块每日发帖之星
日期:2016-05-03 06:20:00数据库技术版块每日发帖之星
日期:2016-04-21 06:20:00数据库技术版块每日发帖之星
日期:2016-01-23 06:20:00数据库技术版块每日发帖之星
日期:2015-12-03 06:20:00综合交流区版块每周发帖之星
日期:2015-12-02 15:03:53数据库技术版块每日发帖之星
日期:2015-10-19 06:20:00数据库技术版块每日发帖之星
日期:2015-08-20 06:20:002015年辞旧岁徽章
日期:2015-03-03 16:54:15数据库技术版块每日发帖之星
日期:2016-07-30 06:20:00
6 [报告]
发表于 2007-11-28 22:40 |只看该作者
看看你的第39行吧!

论坛徽章:
1
2015年辞旧岁徽章
日期:2015-03-03 16:54:15
7 [报告]
发表于 2007-12-05 13:01 |只看该作者
属主变量申明符“:”在哪里???
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP