如何让MySQL提示在查询中的值? [英] How to ask MySQL to prompt for values in a query?
问题描述
我做了很多试验和错误与一些SQL查询在MySQL控制台。
选择fname,年龄,地址from person where lname =?
我想得到一个提示,询问lname的值,这样我可以重复查询容易与不同的值。 ??在查询来自Java代码的情况下工作。
在MySQL控制台中是否可以如何?
p>
您可能想创建一个存储过程,例如
DELIMITER //
CREATE PROCEDURE GetPerson(p_lname VARCHAR(50))
BEGIN
SELECT fname,age,address FROM person WHERE lname = p_lname;
END //
DELIMITER;
,然后才能
mysql> CALL GetPerson('smith');
但这只是你可以走的。
mysql
客户端的目的是运行SQL查询(并管理服务),SQL是一种查询语言,不是用于用户交互。
I am doing a lot of trial and error with some SQL query in MySQL console e.g.
select fname, age, address from person where lname = ?;
I want to get a prompt asking me for the value of lname, so that I can repeat the query with different values easily. The ? works in case the query is from Java code.
Is it possible in MySQL console, if yes, how?
This is not possible.
You may want to create a stored procedure such as
DELIMITER //
CREATE PROCEDURE GetPerson(p_lname VARCHAR(50))
BEGIN
SELECT fname, age, address FROM person WHERE lname = p_lname;
END //
DELIMITER ;
and then be able to
mysql> CALL GetPerson('smith');
But this is pretty much as far as you can go.
mysql
client's purpose is to run SQL queries (and manage the service), SQL is a query language, not meant for user interaction.
这篇关于如何让MySQL提示在查询中的值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!