比如 select "name" from serviceclientsinfo.conactnametable where owner='b'
我希望出来的结果的第一行赋值给变量id?

解决方案 »

  1.   

    select colName into @var from table1 where id=10
      

  2.   

    MySQL官方文档 http://dev.mysql.com/doc/refman/5.1/zh/index.html
      

  3.   

    insert into serviceclientsinfo.conactnametable ("name","owner") values ('a','b');
    select "name" into @var from serviceclientsinfo.conactnametable where owner='b';
    select @var;
    我用的是postgresql,使用上面语句报错ERROR: syntax error at or near "@"
      

  4.   

    试试select @name:=name from tablename where id=1
      

  5.   

    SELECT @varname=columnname FROM tablename
    上述语句在SQL SERVER 2008里可执行通过。
      

  6.   


    mysql> select name into @A from area limit 1;
    Query OK, 1 row affected (0.00 sec)mysql> select @A;
    +------+
    | @A   |
    +------+
    | 北京     |
    +------+
    1 row in set (0.00 sec)mysql>
    不过这样的@a是session级别的,只能在当前连接下访问。