函数
/* 函数:函数只会返回一个值,不允许返回一个结果集。函数强调返回值,所以不允许返回多个值的情况,即使是查询语句。多个入参之间使用逗号分隔。 注意事项:在函数中,如果查询的表中字段与参数名相同,需要给字段名前面加上别名,不然在识别的时候有问题,程序不会报错,但查询结果有问题。 */ drop function if exists myf; create function myf(region_code varchar(10)) returns int begin declare c int; -- 定义变量,需要将查询结果赋值给变量select xxx into c; select pm10 from data_region_month t where t.region_code = region_code limit 1 into c; return c; end; select myf('411025'); select myf(region_code) from data_region_month;
存储过程