我的井字遊戲有一部分收集開始用戶的移動,然後更新板。移動變量以字符串開頭,所以我使用substring將字符串和列從字符串中取出,並將它們放入兩個變量i和j中。然後我使用更新聲明來更換電路板。但是,當我這樣做時,它會返回錯誤,並在字段列表中顯示「未知列」。我不明白爲什麼,因爲我已經在程序的頂部聲明瞭兩個變量。Tic-Tac-Toe遊戲在字段列表中的未知列'i'MySQL
編輯:這是我使用的表的代碼:
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;
給予任何幫助將是不勝感激!
你能提供什麼表,你所得到的是錯誤的表定義? 'mysql -u username -p''use database'' describe table' – kshikama