Hi,

Learning about MySQL's stored procedure programming.

trying to do things like count(*) of the # of rows in a specific table.

eg:
DELIMITER $$
DROP PROCEDURE IF EXISTS `test`.`sp_countrows`$$
CREATE [EMAIL PROTECTED] PROCEDURE `sp_countrows`()
BEGIN
  SELECT count(*) AS 'Test1(QTY)' FROM test1;
  SELECT count(*) AS 'Test2(QTY)' FROM test2;
END$$
DELIMITER ;
mysql> call sp_countrows();
+------------+
| Test1QTY) |
+------------+
|       4324 |
+------------+
1 row in set (0.01 sec)

+-----------+
| Test2(QTY) |
+-----------+
|      3116 |
+-----------+
1 row in set (0.01 sec)



When I try to put the table_names as a variable I don't get anything

eg:
DELIMITER $$
DROP PROCEDURE IF EXISTS `dbxmldmysql`.`sp_countrows2`$$
CREATE PROCEDURE `dbxmldmysql`.`sp_countrows2` (in_table_name
varchar(30))
BEGIN
  SELECT count(*) AS 'QTY' FROM in_table_name;
END$$
DELIMITER ;

mysql>call sp_countrows2();
ERROR 1318 (42000): Incorrect number of arguments for PROCEDURE
dbxmldmysql.sp_countrows2; expected 1, got 0
mysql> call sp_countrows2(test1);
ERROR 1054 (42S22): Unknown column 'test1' in 'field list'
mysql> call sp_countrows2('test1');
ERROR 1146 (42S02): Table 'test.in_table_name' doesn't exist

why does it expect a literal name in the "FROM" clause?



-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to