[英]How to insert dynamic parameter in mysql statement?
I am using mysql as a database and this is the query 我正在使用mysql作为数据库,这是查询
select
job_id,
area_set,
area_subset,
worker_type,
job_posting_name,
job_location,
start_date,
end_date,
description,
is_template,
template_name,
is_draft,
no_of_post,
is_open,
pay_rate,
is_completed,
create_date,
contractor_company_name,
jobs.user_id
from
jobs, contractor_company
where job_id not in (select job_id from job_response where job_response.user_id = 864)
and is_template in (0,1)
and is_draft in (0,0)
and is_open in (1,1)
and is_completed in (0,0)
and contractor_company.contractor_company_id = (select contractor_company_id from contractor_survey_question
where contractor_survey_question.user_id = jobs.user_id)
and jobs.user_id IN ( select user.user_id from user where user.phone_country_code =(select user.phone_country_code from user
where user.user_id=864 )) and area_set = 10 and area_subset in(78,79)
order by create_date desc;
Here in area_subset there may be different number of parameters. 在area_subset中,可能有不同数量的参数。
And I am calling this statement from js adapter like 我从js适配器调用此语句,例如
select
job_id,
worker_type,
job_posting_name,
job_location,
start_date,
end_date,
description,
is_template,
template_name,
is_draft,
no_of_post,
is_open,
pay_rate,
is_completed,
create_date,
contractor_company_name,
jobs.user_id
from
jobs, contractor_company
where job_id not in (select job_id from job_response where job_response.user_id = ?)
and is_template in (?,?)
and is_draft in (?,?)
and is_open in (?,?)
and is_completed in (?,?)
and contractor_company.contractor_company_id = (select contractor_company_id from contractor_survey_question
where contractor_survey_question.user_id = jobs.user_id)
and jobs.user_id IN ( select user.user_id from user
where user.phone_country_code =(select user.phone_country_code from user
where user.user_id=? )) and area_set = ? and area_subset in(?,?)
order by create_date desc;
for example there may be more than 2 parameters in area_subset then how can I pass to this query. 例如,area_subset中可能有两个以上的参数,那么如何传递给该查询。
Kindly help 请帮助
CREATE DEFINER=`root`@`localhost` PROCEDURE `test`(input VARCHAR(15))
BEGIN
SET @input = input;
if @input="asc" then
SET @sort = " order by ActivityLogKey asc";
elseif @input = "desc" then
SET @sort = " order by ActivityLogKey desc";
else
SET @sort ="";
end if;
SET @query = CONCAT('select * from activitylog ',@sort,' limit 0, 5');
PREPARE stmt FROM @query;
EXECUTE stmt;
DEALLOCATE PREPARE stmt;
END
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.