create procedure processorders()
 begin
 declare done boolean default 0;
 declare o int;
 declare t decimal(8,2);
 declare ordernumbers cursor
 for
 select order_num from orders;
 declare continue handler for sqlstate '02000' set done=1;
 create table if not exists ordertotals(order_num int, total decimal(8,2));
 open ordernumbers;
 repeat
 fetch ordernumbers into o;
 call ordertotal(o, 1, t);
 insert into ordertotals(order_num, total) values(o, t);
 until done end repeat;
 close ordernumbers;
 end;
 //在MySQL创建存储过程如上面代码,在里面我有用create table if not exists ordertotals(order_num int, total decimal(8,2));创建一个表,语句执行正常,没报错,过后用show tables却看不到ordertotals这张表,是什么问题?还是我上面语句有什么地方是不对的?请高人帮忙指出下。非常感谢!

解决方案 »

  1.   

    表ordertotals?是否在其它数据库中?
      

  2.   

    查了,可以肯定没有。
    MySQL5.1版本,而且已经切换到当前数据库下面了。
      

  3.   

    我也觉得是到别的库里去了。
    执行这个存储过程之前先USE DBNAME,指定数据库。
      

  4.   

    在SP中加入USE DBNAME,再运行试试
      

  5.   

    可以确定没有,而且也确定use,所以很奇怪。。
      

  6.   

    ERROR 1314 (0A000): USE is not allowed in stored procedures
      

  7.   

    declare continue handler for sqlstate '02000' set done=1;
    select 1;
     create table if not exists ordertotals(order_num int, total decimal(8,2));
    select 2;
     open ordernumbers;看看此句执行没有
      

  8.   

    没有,一回车,它就出现:
    Query OK, 0 rows affected (0.00 sec)
    其他什么都没有。
      

  9.   

    建立1个临时表,1个字段,看看建表语句执行没有
    create table if not exists ordertotals(order_num int, total decimal(8,2));
    insert into 临时表 values(1)
      

  10.   


    create procedure p_create()
    begin
      create table if not exists ordertotals(order_num int, total decimal(8,2));
      insert into ordertotals values(1,10);
      select * from ordertotals;
    end;
    mysql> call p_create();
    +-----------+-------+
    | order_num | total |
    +-----------+-------+
    |         1 | 10.00 |
    |         1 | 10.00 |
    +-----------+-------+
    2 rows in set (0.17 sec)Query OK, 0 rows affected, 1 warning (0.20 sec)mysql> call p_create();
    +-----------+-------+
    | order_num | total |
    +-----------+-------+
    |         1 | 10.00 |
    |         1 | 10.00 |
    |         1 | 10.00 |
    +-----------+-------+
    3 rows in set (0.06 sec)Query OK, 0 rows affected, 1 warning (0.06 sec)mysql>
      

  11.   

    好像又不行了,现在按下面的语句创建表也不成功:
    create procedure processorders()
    begin
      create table if not exists testtest(order_num int, total decimal(8,2));
    end;我表名随便取的,都不会创建了。。
    有兄弟知道的吗?
      

  12.   

    语句上应该没有问题,如果怀疑你可以测试一下。 create procedure processorders()
     begin 
     create table if not exists ordertotals(order_num int, total decimal(8,2));
     end;
     //你是不是根本没有执行你的存储过程啊。你有 call processorders() 吗?
      

  13.   


    大大,我现在没环境试,不过,我觉得你说对我的问题所在了,应该调用下call的,给忘记了,呵呵,谢谢楼上几位兄弟的热心解答。