Mysql存储过程选择列到OUT参数

时间:2013-08-26 00:41:16

标签: mysql stored-procedures out-parameters

我有一个与此类似的存储过程,当我尝试保存它时,我收到此错误:

  

未声明的变量:my_column

CREATE PROCEDURE p (OUT column_param VARCHAR(25))
BEGIN
    SELECT my_column INTO coumn_param limit 1;
END;

为什么我不能选择要返回的列?

这是我在程序中的实际查询:

select latitude into lat, longitude into lon
from cities cc
inner join countries c on cc.country_id = c.country_id
inner join regions r on cc.region_id = r.region_id and c.country_id = r.country_id
left join locations l on cc.city_id = l.city_id
where 
city = coalesce(cty, city) and
country = coalesce(ctry, country) and
region = coalesce(reg, region)
limit 1;

1 个答案:

答案 0 :(得分:4)

INTO子句的语法不正确

假设您的查询本身正确且功能正常,并且您声明了latlon个变量,则更改此部分

select latitude into lat, longitude into lon

SELECT latitude, longitude INTO  lat, lon

这是 SQLFiddle 演示