gpt4 book ai didi

mysql - (STOREDPROC) 生成的 SELECT 语句 : looking for the right syntax to use near NULL

转载 作者:行者123 更新时间:2023-11-30 22:31:54 26 4
gpt4 key购买 nike

我在创建表适配器时使用存储过程。这是我的语法:

DELIMITER $$

DROP PROCEDURE IF EXISTS `lcs_rdb`.`sp_EmployeeListReport`$$

CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_EmployeeListReport`(in where_clause TEXT)
BEGIN
SET @sql = CONCAT("SELECT
emp.employee_id,
group_concat(distinct `ext`.`extension_number` separator ',') AS extension_number,
emp.employee_lastname, emp.employee_firstname,
dept.department_description,
divs.division_description,
grps.group_description,
st.site_name, emp.audit_date,
group_concat(distinct `cst_ctr`.`cost_center_description` separator ',') AS cost_center_description
FROM employees emp INNER JOIN
employee_extensions emp_ext ON emp_ext.employee_id = emp.employee_id INNER JOIN
extensions ext ON ext.extension_id = emp_ext.extension_id INNER JOIN
departments dept ON emp.department_id = dept.department_id INNER JOIN
divisions divs ON dept.division_id = divs.division_id INNER JOIN
groups grps ON divs.group_id = grps.group_id INNER JOIN
sites st ON emp.site_id = st.site_id LEFT OUTER JOIN
employee_cost_centers emp_cstctr ON emp.employee_id = emp_cstctr.employee_id LEFT OUTER JOIN
cost_centers cst_ctr ON emp_cstctr.cost_center_id = cst_ctr.cost_center_id
where ", where_clause ,"");
PREPARE stmt FROM @sql;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END$$

DELIMITER ;

这是我执行时的错误:
“生成的 SELECT 语句。 您的 SQL 语法有误;检查与您的 MySQL 服务器版本对应的手册,了解在第 1 行的“NULL”附近使用的正确语法”

我认为,问题出在 where 子句中。但我不知道如何解决它。请帮忙。谢谢。

最佳答案

如果任何值为 NULL

CONCAT() 返回 NULL。也许你想要这样的东西:

CONCAT('select . . .',
COALESCE(where_clause, '1 = 1'))

关于mysql - (STOREDPROC) 生成的 SELECT 语句 : looking for the right syntax to use near NULL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33663317/

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