没有接触过存储过程,请朋友帮忙写一个,谢谢了。要求就是写传一个SQL语句进去,然后获得这个sql语句取得的记录的条数。

解决方案 »

  1.   

    DELIMITER $$DROP PROCEDURE IF EXISTS `test`.`sp_test`$$CREATE DEFINER=`root`@`localhost` PROCEDURE `sp_test`()
    BEGIN
    select count(*) from song;
    END$$DELIMITER ;==============
    call sp_test();
    =============
    21
      

  2.   

    delimiter $$
    create procedure count_sql(in csql varchar(100))
    begin
    declare s varchar(100);
    set @s=csql;
    prepare stmt from @s;
    execute stmt;
    deallocate prepare stmt;
    end;
    $$call count_sql('select count(*) from tablename');