错误代码:1054。“字段列表”中的未知列

Posted

技术标签:

【中文标题】错误代码:1054。“字段列表”中的未知列【英文标题】:Error Code: 1054. Unknown column in 'field list' 【发布时间】:2016-02-09 01:32:07 【问题描述】:

请帮助我正在尝试执行以下存储过程。我收到一条错误消息,指出“bpc2016.entity”。当我在行业CY 视图中删除对行业PY 的引用时,错误消失了。请帮助表和列存在于数据库中。

CREATE DEFINER=`root`@`localhost` PROCEDURE `getAbudgetnow`()
BEGIN
CREATE OR REPLACE VIEW industryPY
AS
SELECT
alet.area AS 'area',
alet.industry_description AS 'industry_desc',
alet.industry AS 'industry',
alet.percentage AS 'perc',
ref_data.product AS 'product',
ref_data.pz AS 'pz',
ref_data.rate AS 'amount'
FROM
alet
RIGHT JOIN
ref_data ON (alet.industry = ref_data.industry and alet.area = ref_data.area)
WHERE alet.industry IS NOT NULL;

CREATE OR REPLACE VIEW industryCY
AS
SELECT
bpc2016.entity AS 'entity',
bpc2016.plant AS 'plant',
bpc2016.product_desc AS 'product_desc',
bpc2016.product AS 'product',
bpc2016.customer AS 'customer',
bpc2016.route AS 'route',
bpc2016.pz_desc AS 'pz_desc',
bpc2016.pz AS 'pz',
bpc2016.amount AS 'amount',
industryPY.area AS 'area',
industryPY.industry_desc AS 'industry_desc',
industryPY.industry AS 'industry',
industryPY.perc AS 'percentage',
industryPY.amount AS 'PYamount',
TRUNCATE(bpc2016.amount*industryPY.perc,2) AS 'budget_2016_vol'
FROM
bpc2016
FULL JOIN
industryPY ON (bpc2016.pz = industryPY.pz and bpc2016.product = industryPY.product);

END

'bpc2016', (\nentity varchar(255) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT \'\',\nplant varchar(255) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT \'\',\nproduct_desc varchar(255) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT \'\',\nproduct varchar(255) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT \'\',\ninterplant varchar(255) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT \'\',\ncustomer varchar(255) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT \'\',\nroute varchar(255) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT \'\',\npz_desc varchar(255) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT \'\',\npz varchar(255) CHARACTER SET latin1 COLLATE latin1_bin NOT NULL DEFAULT \'\',\namount float NOT NULL DEFAULT \'0\' \n) ENGINE=InnoDB 默认字符集=latin1'

【问题讨论】:

错误信息很清楚 - 它不能引用字段 bpc2016.entity。您应该发布 bpc2016 的创建表语句 bpc 2016 表已经存在于带有数据的数据库中 @the_big_blackbox :但它似乎没有实体字段...显示表定义。 另外 mysql 也没有 FULL JOIN 至少不是直接 大家好,包括表定义 【参考方案1】:

感谢所有帮助,这似乎是问题所在 - 当我将完整连接替换为 rightleft join 时,Mihai 是正确的“mysql 没有 FULL JOIN 至少不是直接的”。程序执行。

【讨论】:

【参考方案2】:

您可以重新定义分隔符,以便告诉解析器语句在您的过程中的何处结束;

DELIMITER $$
CREATE DEFINER=`root`@`localhost` PROCEDURE `getAbudgetnow`()
BEGIN

  CREATE OR REPLACE VIEW industryPY 
  AS
  SELECT
  alet.area AS 'area',
  alet.industry_description AS 'industry_desc',
  alet.industry AS 'industry',
  alet.percentage AS 'perc',
  ref_data.product AS 'product',
  ref_data.pz AS 'pz',
  ref_data.rate AS 'amount'
  FROM
  alet
  RIGHT JOIN
  ref_data ON (alet.industry = ref_data.industry and alet.area = ref_data.area)
  WHERE alet.industry IS NOT NULL;

  CREATE OR REPLACE VIEW industryCY
  AS
  ...
  ;


END $$
DELIMITER ;

【讨论】:

以上是关于错误代码:1054。“字段列表”中的未知列的主要内容,如果未能解决你的问题,请参考以下文章

错误代码:1054。存储过程中“字段列表”中的未知列“abcdef”

MySQL 错误 #1054 -“字段列表”中的未知列

找不到列:1054“字段列表”中的未知列“0”-Laravel-我的代码中的任何地方都没有0列

错误 #1054 - 尝试将 CSV 文件导入数据库时​​,字段列表中出现未知列

#1054 - '字段列表'中的未知列 'id' - phpMyAdmin

SQLSTATE [42S22]:未找到列:1054 laravel 4 中“字段列表”中的未知列“id”