我在MySQL中编写了一个函数来获取带有ip-address的id。
CREATE FUNCTION `get_hwid_with_ipex`(`ipex` VARCHAR(15)) RETURNS int(4) unsigned
BEGIN
DECLARE hwid INT(4);
SELECT `id` INTO hwid FROM `hardware` WHERE `ip_external` = ipex;
RETURN COALESCE(hwid, 'HWID not found');
END
在我的脚本中,我尝试得到这样的id:
id=$(mysql -h$host -u$user -p$password -e "SELECT installscript_systems_test.get_hwid_with_ipex('127.0.0.1');")
mysql -h$host -u$user -p$password -e "INSERT INTO installscript_systems_test.logging_actions (id, hwid, action, status, created, modified) VALUES (NULL, '$id', 'testing the script', 'successful', NOW(), NOW());"
$ id的结果是:
installscript_systems_test.get_hwid_with_ipex('127.0.0.1') 1
如何分割我只获得id(例如1)?
答案 0 :(得分:0)
我把它改成了
id=$(mysql -h$host -u$user -p$password -e "SELECT installscript_systems_test.get_hwid_with_ipex('127.0.0.1') AS '';")
使用AS '';
可行。我的结果现在是1
是表演吗?