我正在编写一个 mysql 函数来删除一行并在键值对表中进行备份。我能做的最多,但无法从检索到的列名中选择一个值
CREATE FUNCTION delete_item (
item_id_val int,
cur_usr_id int,
item_type_val varchar(45),
current_purpose varchar(45),
cur_date datetime
) RETURNS INT
BEGIN
declare col_name varchar(45);
declare no_of_cols int;
declare ind int;
declare c1 cursor for select column_name from information_schema.columns where table_name='tbl_name';
select count(column_name) from information_schema.columns where table_name='tbl_name' into no_of_cols;
open c1;
while no_of_cols > 0 do
fetch c1 into col_name;
insert into deleted_data(tbl_name,field_nm,val,activity_date) values('tbl_name',col_name,
(**select col_name from tbl_name where item_id=item_id_val**),cur_date);
set no_of_cols = no_of_cols-1;
end while;
close c1;
return 1;
粗体文本(*ed text)将列名本身保存在 value 的位置。我需要将该列名的值存储在该表中。需要帮助的家伙