gpt4 book ai didi

mysql - 1054 - 'cliente' 中的未知列 'where clause'

转载 作者:行者123 更新时间:2023-11-30 23:06:21 24 4
gpt4 key购买 nike

set @tabela='cliente';

set @campo='codigo';

set @t1 = concat('SELECT count(0) FROM information_schema.COLUMNS WHERE
information_schema.COLUMNS.TABLE_NAME =',@tabela,' AND
information_schema.COLUMNS.COLUMN_NAME =',@campo);

PREPARE teste FROM @t1;

execute teste;

============================================= ================

[SQL] set @tabela='cliente'; Affected rows: 0 Time: 0.003ms

[SQL] set @campo='codigo'; Affected rows: 0 Time: 0.001ms

[SQL]
set @t1 = concat('SELECT count(0) FROM information_schema.COLUMNS WHERE information_schema.COLUMNS.TABLE_NAME =',@tabela,' AND information_schema.COLUMNS.COLUMN_NAME =',@campo);
Affected rows: 0
Time: 0.001ms

[SQL] PREPARE teste FROM @t1; [Err] 1054 - “where 子句”中的未知列“cliente”

*为什么? *

最佳答案

您的选择看起来像这样:

SELECT count(0) FROM information_schema.COLUMNS
WHERE information_schema.COLUMNS.TABLE_NAME = cliente

什么时候应该是这样的:

SELECT count(0) FROM information_schema.COLUMNS
WHERE information_schema.COLUMNS.TABLE_NAME = 'cliente'

添加必要的引号。我不知道确切的语法。大概是

TABLE_NAME =''',@tabela,'''

TABLE_NAME =\'',@tabela,'\' 

编辑:我已经查过了。根据http://dev.mysql.com/doc/refman/5.0/en/string-literals.html两个版本都是正确的。

关于mysql - 1054 - 'cliente' 中的未知列 'where clause',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21729680/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com