[英]How to pass shell script variable to mysql stored procedure as OUT parameter?
I want to pass shell script variable as OUT parameter to Mysql stored proc. 我想将shell脚本变量作为OUT参数传递给Mysql存储过程。 Stored proc is like this: 存储过程是这样的:
SET sql_mode = 'ANSI_QUOTES';
DELIMITER $$
CREATE PROCEDURE GetTypeSchemaFromAttributeTable(OUT ColumnType VARCHAR (512), OUT ColumnCharset VARCHAR(128), OUT ColumnCollationName VARCHAR(128))
BEGIN
SELECT `COLUMN_TYPE` AS ColumnType, `CHARACTER_SET_NAME` AS ColumnCharset, `COLLATION_NAME` AS ColumnCollationName FROM information_schema.COLUMNS WHERE `TABLE_SCHEMA`='example' AND `TABLE_NAME`='Attribute' AND `COLUMN_NAME`='Type';
END $$
DELIMITER ;
Then my shell script: 然后是我的shell脚本:
mysql --host="blabla" --user="blabla" --password="blabla" --database="blabla" -e "CALL GetTypeSchemaFromAttributeTable(@type, @charset, @collation)"
echo $type
echo $charset
echo $collation
But unfortunately, it's not working. 但不幸的是,它没有用。 All these variables are empty. 所有这些变量都是空的。 Could someone suggest what I should do? 有人可以建议我应该做什么吗?
Assign output of mysql command to variable and then split it using awk or other utility Use -sN in mysql to hide column name and table layout 将mysql命令的输出分配给变量,然后使用awk或其他实用程序将其拆分使用mysql中的-sN隐藏列名和表布局
output=`mysql --host="blabla" --user="blabla" --password="blabla" --database="blabla" -sN -e "CALL GetTypeSchemaFromAttributeTable(@type, @charset, @collation)"`
$type=`echo $output | awk '{ print $1 }'`
$charse=`echo $output | awk '{ print $2 }'`
$collation=`echo $output | awk '{ print $3 }'`
echo $type
echo $charset
echo $collation
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.