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
求改正

解决方案 »

  1.   

    DELIMITER $$
    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 ;
      

  2.   

    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 ;
      

  3.   

    一样的,
    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 ;
      

  4.   

    找到问题了我的参数不应该在字符串里
    '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;'
    是不对的
      

  5.   

    问题找到了,可是怎么解决呢?
    term 还好说,是char型的,可以链进去
    那no int型的 怎么连入字符串呢?
      

  6.   

    concat 并没有把存储过程中的参数(no,term)的值链入字符串,
    假设我我掉用这个过程,参数为(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';
      

  7.   

    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,'\'');
      

  8.   

    MYSQL中使用PREPARE, EXECUTE