迭代时动态组装SQL语句去执行就可以:
$data = [['name' => 'zs', 'addr' => 'china'],
['name' => 'ls', 'addr' => 'china'],
['name' => 'ww', 'addr' => 'china'],
]
foreach ($data as $value) {
$name = $value['name']
$addr = $value['addr']
$sql = "INSERT INTO tablename (name, addr) VALUES ('$name', '$addr')"
$message = add($sql) ? '插入成功' : '插入失败'
echo $message
}
function add ($sql) {
mysql_query($sql)
return mysql_affected_rows()
}
CREATE PROCEDURE init_reportUrl()BEGIN
DECLARE s INT DEFAULT 0
DECLARE r_id bigint(10)
DECLARE report CURSOR FOR select distinct id as r_id FROM ReportHotLine
DECLARE CONTINUE HANDLER FOR NOT FOUND SET s=1
-- 打开游标
open report
-- 将游标中的值赋值给变量,注意:变量名不要和返回的列名同名,变量顺序要和sql结果列的顺序一致
fetch report into r_id
-- 当s不等于1,也就是未遍历完时,会一直循环
while s<>1 do
-- 执行业务逻辑
UPDATE wh_csyx . dy_pres30207800013_001_local a
JOIN ReportHotLine b ON a.gdId = b.ID
AND b.createtime = ( SELECT max( createtime ) FROM ReportHotLine WHERE ID = r_id )
SET blms = b.banliInfo where a.gdId =r_id
-- 将游标中的值再赋值给变量,供下次循环使用
fetch report into r_id
-- 当s等于1时表明遍历以完成,退出循环
end while
-- 关闭游标
close report
END
call init_reportUrl()
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)