table
id name number
1 fdfdfd 3223
2 dfdfdf 4566
存过程如下:
create procedure Ptest(in id int)
begin
select * from table where id=id;
end;//
call Ptest('1')//
将得到
第一行。
问题是:
我要实理,只定义,输出name,或number只要一列,如何实现呢?就是,我让他
类似这样一个函数
function(id,lie){
select lie from table where id = id
}因此我的过程这样写,但不写变量如何处理
create procedure Ptest(in id int,in lie varchar(20))
begin
select lie from table where id=id;
end;//
call Ptest('1')//
输出的结果不对。应该怎么写啊???

解决方案 »

  1.   

    delimiter $$
    create procedure Ptest(in id1 int,in lie varchar(20))
    begin
    set @asql=concat('select ',lie,' from table where id=',id1);
    prepare stml from @asql;
    ecexute stml;
    end$$
    delimiter ;
      

  2.   

    极为感谢,太谢谢你了。我昨晚子时尚未睡觉,苦苦寻求答案,也未找到。
    prepare stml from @asql;
    ecexute stml;
    手册里没有说明啊?
    百度也没有啊?
    谢谢你了。我还有一问,就是如何使用alert修改一个存储过各,手册里也没有,我论坛也没有啊?
    谢谢了,
    就是,如何使用alert 将Ptest修改为
    Ptest(in id1 int,in lie varchar(20))
    insert into table (id,lie) values (id1,22)
    谢谢了,能给一个范例了。
      

  3.   

    ecexute stml;->EXECUTE stml;写错了
    set @asql=concat('insert into table (id,',lie,') values (',id1,'22)');
    prepare stml from @asql;
    execute stml;
      

  4.   


    怎么修改啊?我以前都是drop再新建,连个范例
    这样吗?
    alert procedure pTest aspTest (in id1 int)
    begin
    select id,number,po from caseinfo where id = id1;
    end//
      

  5.   

    如果你是在命令行下输入的,只有先DROP,再建立
    如果你用图形化管理工具,可以直接修改
      

  6.   

    洒家给mysql写过信,目前无方法法使用修改