gpt4 book ai didi

MySQL,过程不会被调用

转载 作者:行者123 更新时间:2023-11-29 14:29:30 25 4
gpt4 key购买 nike

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

关系:

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>

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

最佳答案

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

mysql> CALL firePower('Bismarck', @p)//
Query OK, 0 rows affected, 1 warning (0.00 sec)

关于MySQL,过程不会被调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10285424/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com