当我尝试执行以下查询时:
SELECT filesinfo.IsFolder INTO @IsFolder, filesinfo.FileName
FROM filesinfo
WHERE filesinfo.FileID = 1;
发生以下错误:
[ SQL ] SELECT filesinfo.IsFolder INTO @IsFolder, filesinfo.FileName FROM filesinfo WHERE filesinfo.FileID = 1; [呃] 1327 - 未声明的变量:filesinfo
但是当删除第二个参数时:
SELECT filesinfo.IsFolder INTO @IsFolder
FROM filesinfo
WHERE filesinfo.FileID = 1;
没有发生错误
答案 0 :(得分:1)
请你试试这个,假设你已经正确地声明了变量并且你在表中有一个名为FileName的列..:
SELECT @IsFolder:=IsFolder, FileName
FROM filesinfo
WHERE FileID = 1;
@Mahmoud Gamal给予我SQLFIDDLE的全部功劳,请查看它以查看查询的实时结果:
如果要选择多列,可以声明多个变量并将其设置如下:
SELECT @IsFolder:=IsFolder, @FileName:=FileName
FROM filesinfo
WHERE FileID = 1;