sql语句中的任何部分都可以作为参数。
DROP PROCEDURE if exists insertdata;
delimiter //
CREATE PROCEDURE insertdata(IN table_name varchar(255))
begin
declare var_sql varchar(800);
set var_sql = concat_ws(‘ ‘, ‘select count(*) from ‘, table_name,‘ where c_purchase_id is null‘);
set @sql = var_sql;
PREPARE s1 from @sql;
EXECUTE s1;
deallocate prepare s1;
end //
delimiter ;
call insertdata(‘table_name‘);
时间: 2024-10-24 15:41:12