gpt4 book ai didi

mysql - #1064.您的 SQL 语法有错误;检查与 MySQL 服务器版本相对应的手册,了解在第 1 行 'NULL' 附近使用的正确语法

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

我有以下代码。我收到如下错误:

Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'NULL' at line 1

MySQL 代码:

set session group_concat_max_len = 8192*50;
SET @sql = NULL;

SELECT
GROUP_CONCAT(DISTINCT
CONCAT(
'select id, "',
c.column_name,
'" as word from limesurvey.lime_survey_697389 '
) SEPARATOR ' UNION ALL '
) INTO @sql
FROM information_schema.columns c
where c.table_name = 'limesurvey.lime_survey_697389'
and c.column_name like '697389%'
order by c.ordinal_position;


SET @sql
= CONCAT('select id, word
from
(', @sql, ') x order by id');


PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;

有人可以帮忙吗?我是 MySQL 新手。

最佳答案

您不能为@sql 定义NULL 值。相反,你可以尝试这样:

SET @sql = '';

<罢工>

编辑:

您需要在存储的程序或函数中执行上述代码。 MYSQL 文档说:

MySQL supports the IF, CASE, ITERATE, LEAVE LOOP, WHILE, and REPEAT constructs for flow control within stored programs.

关于mysql - #1064.您的 SQL 语法有错误;检查与 MySQL 服务器版本相对应的手册,了解在第 1 行 'NULL' 附近使用的正确语法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32858957/

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