调用mysql存储过程,没有报错 数据库里面却没有值。
存储过程代码:
create procedure saveorderitem(oid bigint,pid bigint,pq int,pname varchar(32),pnumber int,pprice double)
begin
declare updatenumber int;
declare exit handler for sqlexception rollback;
set updatenumber=pnmuber-pq;
insert into orderitem(pname,pid,price,number,oid) values(pname,pid,pprice,pq,oid);
update product set number=updatenumber where pid=pid;
commit;
end;

解决方案 »

  1.   

    是什么原因,急啊!orderitem的值为空,product表也没有被更新!
      

  2.   

    先试一下这个吧,你的变量名和字段名重复了。没有你的表结构和测试数据,无法帮你测试。create procedure saveorderitem(v_oid bigint,v_pid bigint,v_pq int,v_pname varchar(32),v_pnumber int,v_pprice double)
    begin
    declare v_updatenumber int;
    declare exit handler for sqlexception rollback;
    set v_updatenumber=v_pnmuber-v_pq;
    insert into orderitem(pname,pid,price,number,oid) values(v_pname,v_pid,v_pprice,v_pq,v_oid);
    update product set `number`=v_updatenumber where pid=v_pid;
    commit;
    end;
      

  3.   

    product表:
    Field    Type                 NuLL  Key  Default   Extra
    pid  bigint(20) unsigned      NO    PRI   NULL     auto_increment
    name  varchar(32)             No    UNI   NULL
    userid bigint(20)unsigned     No    Mul   Null
    imagepath varchar(400)        no          Null
    intro     varchar(200)        no          null
    number    varchar(15)         no          null
    upload_time date              no          null
    price       varchar(15)       no          nullorderitem表:Field         Type                 NuLL    Key   Default         Extra
    orderitemid  bigint(20) unsigned     NO    PRI   NULL           auto_increment
    pname        varchar(15)             No    UNI   NULL
    pid           bigint(20)unsigned     No    MUL   NUll
    number      int(10)unsigned          no          NUll
    price        double                  No          NUll
    oid          bigint(20)unsigned      No    MUL   NUllproduct表里面有条数据了,主键值是1;其他表没有数据。
    测试语句:
    call saveorderitem(1,1,2,‘x’,5 ,50))
    不知道什么原因就是不执行!
    是不是外键影响了!
      

  4.   

    给出你的create table 语句,和 insert 语句。建议你列出你的表结构,并提供测试数据以及基于这些测试数据的所对应正确结果。
       参考一下这个贴子的提问方式http://topic.csdn.net/u/20091130/20/8343ee6a-417c-4c2d-9415-fa46604a00cf.html
       
       1. 你的 create table xxx .. 语句
       2. 你的 insert into xxx ... 语句
       3. 结果是什么样,(并给以简单的算法描述)
       4. 你用的数据库名称和版本(经常有人在MS SQL server版问 MySQL)
       
       这样想帮你的人可以直接搭建和你相同的环境,并在给出方案前进行测试,避免文字描述理解上的误差。   
      

  5.   

    谢谢了,原来真的是外键问题,我直接在orderitem表中插入都不行.