字段列表 MySQL 中的 Tic-Tac-Toe 游戏未知列 'i'

Tic-Tac-Toe Game Unknown column 'i' in field list MySQL

我的 Tic-tac-toe 游戏有一部分会收集初始用户的着法,然后更新棋盘。 move 变量以字符串形式开始,因此我使用子字符串从字符串中获取列和行,并将它们放入两个变量 i 和 j 中。然后我使用更新语句来更改板。然而,当我这样做时,它返回错误 "Unknown column 'i' in field list"。我不明白为什么我在过程的顶部声明了两个变量。

编辑:这是我正在使用的 table 的代码:

CREATE TABLE `tictactoe_4213`.`grid` 
(`TTT` INT NOT NULL,
 `A` VARCHAR(45) NULL,
 `B` VARCHAR(45) NULL,
 `C` VARCHAR(45) NULL,
  PRIMARY KEY (`TTT`));

Insert into grid
values (1, null, null, null),
(2, null, null, null),
(3, null, null, null);

代码如下:

create procedure tictactoe(input varchar(4))
begin

declare i varchar(1);
declare j varchar(1);

...

if input like 'bu__' then

  select substring(input, 3, 1) into i;
  select substring(input, 4, 1) into j;

if i not in ('A', 'B', 'C') then
    select 'Invalid Letter. Please enter a letter between A and C for the column.';
end if;

if j not in (1, 2, 3) then
    select 'Invalid Number. Please enter a number between 1 and 3 for the row.';
end if;

update grid
set i = 'U'
where ttt = j;

select * from grid;
end if;

如有任何帮助,我们将不胜感激!

假设我有这个模式。现在好了。

create table grid
(
    ttt int not null
);

这是我的存储过程

drop procedure if exists asdf;

delimiter $$
create procedure asdf(input varchar(40))
begin

declare i varchar(1);
declare j varchar(1);

set i='a';

update grid
set i = 'U'
where ttt = j;

if i not in ('A', 'B', 'C') then
    select 'hello' as aMsg;
else
    select '2222' as aMsg;
end if;

end
$$
delimiter ;

我称之为

call asdf('ignore');

我收到确切的错误消息

Error Code: 1054. Unknown column 'i' in 'field list'

所以 i 不是 table grid

中的列