简体   繁体   English

插入参数后,如何在SQL中输出参数的值?

[英]How do I output the value of a parameter in SQL after it has been inserted?

Is it possible to retrieve the SQL statement with the values of parameters after it has been set and inserted into the SQL component? 设置并插入SQL组件后,是否可以使用参数值检索SQL语句?

SQL Statement: SQL语句:

SELECT * FROM SomeTable
WHERE SomeColumn = :pSomeValue;

Code: 码:

procedure LoadParams(aValue: string);
begin
  Qry.Close;
  Qry.ParamByName('pSomeValue').AsString := aValue;
  MessageDlg(Qry.SQL.Text, mtInformation, [mbOK], 0); // this does not show the value but the parameter name.     
  Qry.Open;
end;

I want to be able to see the statement before it is opened but when I try this now I get the param name instead of the value. 我希望能够在打开语句之前看到该语句,但是当我现在尝试该语句时,我得到的是参数名称而不是值。

Query parameters are normally substituted in the DBMS, ie the values are sent over the connection separately, and not as part of the SQL statement. 查询参数通常在DBMS中替换,即,值是通过连接单独发送的,而不是作为SQL语句的一部分发送的。 If you wish to see the SQL and the values together, the DB's logs might help you with that. 如果您希望同时查看SQL和值,则数据库的日志可能会帮助您。

One thing you can do is duplicate the parameter and put it in the SELECT: 您可以做的一件事是复制参数并将其放入SELECT中:

SELECT :pSomeValueDuplicate AS paraminput, * FROM SomeTable
WHERE SomeColumn = :pSomeValue;

Qry.ParamByName('pSomeValue').AsString := aValue;
Qry.ParamByName('pSomeValueDuplicate').Value := Qry.ParamByName('pSomeValue').Value;

Then you can check the field: paraminput for what you used as input. 然后,您可以检查以下字段:paraminput以用作输入内容。 Somehow I can't get Delphi to use the same parameter twice in 1 query. 不知何故,我无法让Delphi在1个查询中两次使用相同的参数。

SELECT 'SELECT * FROM SomeTable WHERE SomeColumn ='+ :pSomeValueduplicate AS thesqlinput,* FROM SomeTable WHERE SomeColumn = :pSomeValue;

Actually you can do it with just the one parameter: 实际上,您仅需一个参数即可完成此操作:

SELECT 'SELECT * FROM SomeTable WHERE SomeColumn ='+ SomeColumn AS thesqlinput,* FROM SomeTable WHERE SomeColumn = :pSomeValue;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Postgres SQL:如何在更改平均值的现有值后重新计算平均值 - Postgres SQL : how do I recalculate average value, after an existing value from the average has been changed 插入表字段后更改其值 - Changing the value of a table field after it has already been inserted 将值插入 C# 中的 SQL 服务器表后,如何将值加 1? - How do I add 1 to a value after it's inserted into SQL Server table in C#? SQL Server:如何获取插入行的值? - SQL Server: How do I get the value for the row I inserted? 如何选择未超过值的记录 - How do I select records where a value has not been exceeded 从 sqlalchemy 插入数据后,如何在 MySQL 上创建 UUID 触发器? - how to create a UUID trigger on MySQL after data has been inserted from sqlalchemy? 如何创建SQL触发器以根据新插入的行中的值插入新行? - How do I create a SQL trigger to insert new rows based on a value in a newly inserted row? 您如何访问使用ADO.NET事务插入的数据? - How do you access data that has been inserted using a ADO.NET transaction? 应用限制后,可以重新排序SQL选择吗? - Can I reorder SQL selections after the limit has been applied? 我如何确定“插入输出”的顺序正确? - How do I make sure OUTPUT INSERTED is in correct order?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM