选择变量或者在shell脚本中选择mysql选择

时间:2014-10-27 10:32:23

标签: mysql bash shell

我在shell中有这样的mysql脚本:

#!/bin/bash
keyOrPass=$1
intercom=$2
flat=$3
number=$4
mysql -ulogin -ppassword db_name << EOF
select codeGuestEmail, codePrivateEmail from mbus_clients WHERE flat=$flat and domophone=$intercom;
select * from mbusClientKeys where id_client=(select id from mbus_clients WHERE flat=${flat} and domophone=${intercom});
EOF

当我添加第二个查询时出错:right syntax to use near ''当我尝试声明变量并使用select into时,因为它在存储过程中也不起作用。来自previous question的EOF错误也是实际的 的更新 我的尝试也很有效:

SET @id := 1;
select id into @id from mbus_clients WHERE flat=${flat} and domophone=${intercom};

right syntax to use near 'select id into @id from mbus_clients WHERE flat=200

UPDATE2 在之前的更新中错过了分号。 现在工作正常。

1 个答案:

答案 0 :(得分:1)

SET @id := 1;

设置正常,但不是 存储过程中的set id=1应为:=