我在mysql中定義了一個存盤程序,代碼如下:
USE `test`;
DROP procedure IF EXISTS `save_grades`;
DELIMITER $$
USE `test`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `save_grades`()
BEGIN
#此存盤程序創建一個表,對當次考試成績進行備份
declare tb_name varchar(20);
set tb_name=date_format(now(),'%Y');
if length(date_format(now(),'%c'))=2 then
set tb_name=concat(tb_name,'-0');
set tb_name=concat(tb_name,date_format(now(),'%c'));
elseif length(date_format(now(),'%c'))=1 then
set tb_name=concat(tb_name,date_format(now(),'-%c'));
end if;
if length(date_format(now(),'%d'))=2 then
set tb_name=concat(tb_name,'-0');
set tb_name=concat(tb_name,date_format(now(),'%d'));
elseif length(date_format(now(),'%d'))=1 then
set tb_name=concat(tb_name,date_format(now(),'-%d'));
end if;
prepare stm from 'create table `?` (id int primary key,name varchar(10),stunum varchar(10),math int,mathteacherid int,english int,englishteacherid int,physics int,physicsteacherid int)';
set @arg=tb_name;
execute stm using @arg;
prepare stm2 from 'insert into `?` select id,name,stunnum,math,mathteacherid,english,englishteacherid,physics,physicsteacherid from students';
execute stm2 using @arg;
END$$
DELIMITER ;
然后運行時候報錯:
Error Code: 1210. Incorrect arguments to EXECUTE
問題出在哪?
uj5u.com熱心網友回復:
頂上······uj5u.com熱心網友回復:
頂!!!!!!!uj5u.com熱心網友回復:
沒人??????uj5u.com熱心網友回復:
我試了下,是這個函式的使用問題: execute ;但是具體應該怎么用,沒查到;如果一定要弄懂,那你得查檔案了,如果只是為了解決問題,你可以換一種寫法;
建一個臨時表,把你要插入的資料,直接插入到臨時表,在程序結尾地方,洗掉臨時表即可,如果臨時表資料量大,可以先TRUNCATE表,然后在drop;
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/8713.html
標籤:MySQL
