0

我正在尝试编写一个程序来找到一类舰艇的火力。(火力是火炮数量*排量的立方)

关系:

Classes(class, type, country, numGuns, bore, displacement)

到目前为止我尝试过的...

mysql> CREATE PROCEDURE firePower(in className VARCHAR(50), out p int)
-> begin
-> set p = (SELECT numGuns * displacement * displacement * displacement FROM classes
WHERE class = className);
-> end
-> //
Query OK, 0 rows affected (0.35 sec)

mysql> CALL firePower(Iowa, @p)//
ERROR 1054 (42S22): Unknown column 'Iowa' in 'field list'
mysql> SELECT * FROM classes//
+----------------+------+---------+---------+------+--------------+
| class          | type | country | numGuns | bore | displacement |
+----------------+------+---------+---------+------+--------------+
| Bismarck       | bb   | Germany |       8 |   16 |        42000 |
| Iowa           | bb   | USA     |       9 |   16 |        46000 |
| Kongo          | bc   | Japan   |       8 |   14 |        32000 |
| North Carolina | bb   | USA     |       9 |   16 |        37000 |
| Renown         | bc   | Britain |       6 |   15 |        32000 |
| Revenge        | bb   | Britain |       8 |   15 |        29000 |
| Tennessee      | bb   | USA     |      12 |   14 |        32000 |
| Yamato         | bb   | Japan   |       9 |   18 |        65000 |
+----------------+------+---------+---------+------+--------------+
8 rows in set (0.00 sec)

mysql> CALL firePower(Bismarck, @p)//
ERROR 1054 (42S22): Unknown column 'Bismarck' in 'field list'
mysql> 

我的问题是我现在似乎无法调用我的程序......?

4

1 回答 1

1

由于您没有Bismarck在调用中引用,因此该过程将其解释为列名。在其周围添加单引号将与实际字符串匹配。

mysql> CALL firePower('Bismarck', @p)//
Query OK, 0 rows affected, 1 warning (0.00 sec)
于 2012-04-23T17:49:03.383 回答