create procedure check_result(in no int,in term char(20))
begin
declare str char(200);
drop view if exists stu_score;set str=concat('create view if not exists stu_score
as
select cour_name, from score,student,course
where student.no=no and student.name = score.stu_name
and course.term=term;');
execute str;
end
求改正
begin
declare str char(200);
drop view if exists stu_score;set str=concat('create view if not exists stu_score
as
select cour_name, from score,student,course
where student.no=no and student.name = score.stu_name
and course.term=term;');
execute str;
end
求改正
CREATE PROCEDURE check_result(IN NO INT,IN term CHAR(20))
BEGIN
DROP VIEW IF EXISTS stu_score;
SET @str=CONCAT('create view if not exists stu_score
as
select cour_name, from score,student,course
where student.no=no and student.name = score.stu_name
and course.term=term;');
PREPARE stml FROM @str;
EXECUTE stml;
END $$
DELIMITER ;
CREATE PROCEDURE check_result(IN NO INT,IN term CHAR(20))
BEGIN
DROP VIEW IF EXISTS stu_score;
SET @str=CONCAT('create view as
select cour_name, from score,student,course
where student.no=no and student.name = score.stu_name
and course.term=term;');
PREPARE stml FROM @str;
EXECUTE stml;
END $$
DELIMITER ;
DELIMITER $$
CREATE PROCEDURE check_result(IN NO INT,IN term CHAR(20))
BEGIN
DROP VIEW IF EXISTS stu_score;
SET @str=CONCAT('create view stu_score as
select cour_name, from score,student,course
where student.no=no and student.name = score.stu_name
and course.term=term;');
PREPARE stml FROM @str;
EXECUTE stml;
END $$
DELIMITER ;
'create view stu_score as
select cour_name, from score,student,course
where student.no=no and student.name = score.stu_name
and course.term=term;'
是不对的
term 还好说,是char型的,可以链进去
那no int型的 怎么连入字符串呢?
假设我我掉用这个过程,参数为(1000,'tamp')
SET @str=CONCAT('create view stu_score as
select cour_name, from score,student,course
where student.no=no and student.name = score.stu_name
and course.term=term;');这样的话,str 的值就为
create view stu_score as
select cour_name, from score,student,course
where student.no=no and student.name = score.stu_name
and course.term=term;
而我想要的却是
create view stu_score as
select cour_name, from score,student,course
where student.no=10000 and student.name = score.stu_name
and course.term='tamp';
select cour_name, from score,student,course
where student.no=',NO,' and student.name = score.stu_name
and course.term=\'',term,'\'');