MySQL存儲過程傳參數(shù)實(shí)現(xiàn)whereidin(1,2,3,...)示例_MySQL
來源:懂視網(wǎng)
責(zé)編:小采
時間:2020-11-09 18:52:56
MySQL存儲過程傳參數(shù)實(shí)現(xiàn)whereidin(1,2,3,...)示例_MySQL
MySQL存儲過程傳參數(shù)實(shí)現(xiàn)whereidin(1,2,3...)示例_MySQL:bitsCN.com 正常寫法: select * from table_name t where t.field1 in (1,2,3,4...); 當(dāng)在寫存儲過程in里面的列表用個傳入?yún)?shù)代入的時候,就需要用到如下方式: 主要用到find_in_set函數(shù) select * from table_nam
導(dǎo)讀MySQL存儲過程傳參數(shù)實(shí)現(xiàn)whereidin(1,2,3...)示例_MySQL:bitsCN.com 正常寫法: select * from table_name t where t.field1 in (1,2,3,4...); 當(dāng)在寫存儲過程in里面的列表用個傳入?yún)?shù)代入的時候,就需要用到如下方式: 主要用到find_in_set函數(shù) select * from table_nam

bitsCN.com
正常寫法:
select * from table_name t where t.field1 in (1,2,3,4,...);
當(dāng)在寫存儲過程in里面的列表用個傳入?yún)?shù)代入的時候,就需要用到如下方式:
主要用到find_in_set函數(shù)
select * from table_name t where find_in_set(t.field1,'1,2,3,4');
當(dāng)然還可以比較笨實(shí)的方法,就是組裝字符串,然后執(zhí)行:
DROP PROCEDURE IF EXISTS photography.Proc_Test;
CREATE PROCEDURE photography.`Proc_Test`(param1 varchar(1000))
BEGIN
set @id = param1;
set @sel = 'select * from access_record t where t.ID in (';
set @sel_2 = ')';
set @sentence = concat(@sel,@id,@sel_2); -- 連接字符串生成要執(zhí)行的SQL語句
prepare stmt from @sentence; -- 預(yù)編釋一下。 “stmt”預(yù)編釋變量的名稱,
execute stmt; -- 執(zhí)行SQL語句
deallocate prepare stmt; -- 釋放資源
END;
bitsCN.com
聲明:本網(wǎng)頁內(nèi)容旨在傳播知識,若有侵權(quán)等問題請及時與本網(wǎng)聯(lián)系,我們將在第一時間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
MySQL存儲過程傳參數(shù)實(shí)現(xiàn)whereidin(1,2,3,...)示例_MySQL
MySQL存儲過程傳參數(shù)實(shí)現(xiàn)whereidin(1,2,3...)示例_MySQL:bitsCN.com 正常寫法: select * from table_name t where t.field1 in (1,2,3,4...); 當(dāng)在寫存儲過程in里面的列表用個傳入?yún)?shù)代入的時候,就需要用到如下方式: 主要用到find_in_set函數(shù) select * from table_nam