MySQL存儲(chǔ)過(guò)程傳參數(shù)實(shí)現(xiàn)whereidin(1,2,3,...)示例
來(lái)源:懂視網(wǎng)
責(zé)編:小采
時(shí)間:2020-11-09 21:05:41
MySQL存儲(chǔ)過(guò)程傳參數(shù)實(shí)現(xiàn)whereidin(1,2,3,...)示例
MySQL存儲(chǔ)過(guò)程傳參數(shù)實(shí)現(xiàn)whereidin(1,2,3...)示例:正常寫(xiě)法: 代碼如下: select * from table_name t where t.field1 in (1,2,3,4...); 當(dāng)在寫(xiě)存儲(chǔ)過(guò)程in里面的列表用個(gè)傳入?yún)?shù)代入的時(shí)候,就需要用到如下方式: 主要用到find_in_set函數(shù) 代碼如下: select * from table_
導(dǎo)讀MySQL存儲(chǔ)過(guò)程傳參數(shù)實(shí)現(xiàn)whereidin(1,2,3...)示例:正常寫(xiě)法: 代碼如下: select * from table_name t where t.field1 in (1,2,3,4...); 當(dāng)在寫(xiě)存儲(chǔ)過(guò)程in里面的列表用個(gè)傳入?yún)?shù)代入的時(shí)候,就需要用到如下方式: 主要用到find_in_set函數(shù) 代碼如下: select * from table_
正常寫(xiě)法:
代碼如下:
select * from table_name t where t.field1 in (1,2,3,4,...);
當(dāng)在寫(xiě)存儲(chǔ)過(guò)程in里面的列表用個(gè)傳入?yún)?shù)代入的時(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語(yǔ)句
prepare stmt from @sentence; -- 預(yù)編釋一下。 “stmt”預(yù)編釋變量的名稱(chēng),
execute stmt; -- 執(zhí)行SQL語(yǔ)句
deallocate prepare stmt; -- 釋放資源
END;
您可能感興趣的文章:
MySQL左聯(lián)多表查詢(xún)where條件寫(xiě)法示例MySQL Where 條件語(yǔ)句介紹和運(yùn)算符小結(jié)解析mysql left( right ) join使用on與where篩選的差異UCenter info: MySQL Query Error SQL:SELECT value FROM [Table]vars WHERE noteexistsMYSQL where 1=1判定中的作用說(shuō)明MySQL中的max()函數(shù)使用教程MySQL性能優(yōu)化之max_connections配置參數(shù)淺析mysql中max_allowed_packet參數(shù)的配置方法(避免大數(shù)據(jù)寫(xiě)入或者更新失敗)mysql max 與 where 間的執(zhí)行問(wèn)題小結(jié)
聲明:本網(wǎng)頁(yè)內(nèi)容旨在傳播知識(shí),若有侵權(quán)等問(wèn)題請(qǐng)及時(shí)與本網(wǎng)聯(lián)系,我們將在第一時(shí)間刪除處理。TEL:177 7030 7066 E-MAIL:11247931@qq.com
MySQL存儲(chǔ)過(guò)程傳參數(shù)實(shí)現(xiàn)whereidin(1,2,3,...)示例
MySQL存儲(chǔ)過(guò)程傳參數(shù)實(shí)現(xiàn)whereidin(1,2,3...)示例:正常寫(xiě)法: 代碼如下: select * from table_name t where t.field1 in (1,2,3,4...); 當(dāng)在寫(xiě)存儲(chǔ)過(guò)程in里面的列表用個(gè)傳入?yún)?shù)代入的時(shí)候,就需要用到如下方式: 主要用到find_in_set函數(shù) 代碼如下: select * from table_