(STOREDPROC) 生成的 SELECT 语句:寻找在 NULL 附近使用的正确语法
(STOREDPROC) Generated SELECT statement: looking for the right syntax to use near NULL
我在创建 table 适配器时使用存储过程。这是我的语法:
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 子句上。但我不知道如何解决它。请帮忙。谢谢
CONCAT()
returns NULL
如果任何值为 NULL
。也许你想要这样的东西:
CONCAT('select . . .',
COALESCE(where_clause, '1 = 1'))
我在创建 table 适配器时使用存储过程。这是我的语法:
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 子句上。但我不知道如何解决它。请帮忙。谢谢
CONCAT()
returns NULL
如果任何值为 NULL
。也许你想要这样的东西:
CONCAT('select . . .',
COALESCE(where_clause, '1 = 1'))