什么是绑定变量?

发布于 2024-08-19 17:35:37 字数 153 浏览 3 评论 0原文

有一个 cffunction(在 cfc 文档中)可以对用户进行身份验证。它引用一个存储过程并具有一个类型为“out”的cfprocparam。在 Adob​​e CFML 参考中,它表示这意味着“该参数仅用于从数据库系统接收数据。将参数作为绑定变量传递。”

什么是绑定变量?

There is a cffunction (in a cfc document) which authenticates a user. It references a stored procedure and has a cfprocparam which is of type "out". On the Adobe CFML reference it says that means that "the parameter is used to receive data from the database system only. Passes the parameter as a bound variable."

What is a bound variable?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

余罪 2024-08-26 17:35:37

Adobe 的“绑定变量”一词可能是一个错误的选择。我认为他们的意思是它绑定到存储过程内的变量,而不是“保存解释计划”意义上的绑定变量(对于输入变量和输出变量都应该如此)。选择“out”而不是“in”有一些充分的理由,而且还有一些副作用,您可能会发现这些副作用有用,或者如果您没有预料到它们可能会烧伤您。

首先,如果存储过程中的参数类型为“in”,那么大多数数据库不会让您在过程中分配给它 - 当您知道不应更改变量时,这非常有帮助。这是一个 Oracle 示例...

 CREATE PROCEDURE bind_test(p_testin IN NUMBER, p_testout OUT NUMBER) IS
 BEGIN

 -- p_testin  := 100; -- error can not be used as an assignment target
 p_testout := 100;

 END bind_test;

p_testin 无法更改,仅用于“where”子句等地方或启动其他变量,但 p_testout 可以更改。

其次,您可以通过在冷聚变中使用 cfprocparam“variable=” 语法更进一步,并在 ColdFusion 中实际取回更改后的值,而无需通过 cfprocresult。请注意,在此示例中,nTypeIn 和 nTypeOut 的初始值均从 10 开始...

 <cfset nTypeIn  = 10 >
 <cfset nTypeOut = 10 >

 <cfstoredproc  procedure = "bind_test" dataSource = "#ProdDB#" returnCode = "No">
    <cfprocparam type="in"  cfsqltype="CF_SQL_INTEGER" variable="nTypeIn"  value="#nTypeIn#"  null="No"> 
    <cfprocparam type="out" cfsqltype="CF_SQL_INTEGER" variable="nTypeOut" value="#nTypeOut#" null="No"> 
 </cfstoredproc>

 <cfdump var="#nTypeIn#">
 <cfdump var="#nTypeOut#">

在 Oracle 中,测试结束时 nTypeIn 将是 10,但 nTypeOut 将是 100 而不是 10。只要您期望数据库存储过程来更改它。

希望这能让我们对这个问题有更多的了解。

The term "bound variable" may be a bad choice of words from Adobe. I think they mean it is bound to the variable inside the stored proc, not a bind variable in the "save the explain plan" sense (that should be true of both in variables and out variables). There are some good reasons to choose "out" over "in" and there are also side effects that you may find useful or may burn you if you don't expect them.

First off, if a parameter in a stored procedure is type "in" then most databases will not let you assign to it in the proc - very helpful when you know a variable should not be changed. Here is an Oracle example...

 CREATE PROCEDURE bind_test(p_testin IN NUMBER, p_testout OUT NUMBER) IS
 BEGIN

 -- p_testin  := 100; -- error can not be used as an assignment target
 p_testout := 100;

 END bind_test;

p_testin can't be changed, only used in places like "where" clauses or to initiate other variables but p_testout can be changed.

Second, you can take this one step farther by using the cfprocparam "variable =" syntax in cold fusion and actually get back the changed value in ColdFusion without going through a cfprocresult. Notice in this example the initial values for nTypeIn and nTypeOut both start at 10...

 <cfset nTypeIn  = 10 >
 <cfset nTypeOut = 10 >

 <cfstoredproc  procedure = "bind_test" dataSource = "#ProdDB#" returnCode = "No">
    <cfprocparam type="in"  cfsqltype="CF_SQL_INTEGER" variable="nTypeIn"  value="#nTypeIn#"  null="No"> 
    <cfprocparam type="out" cfsqltype="CF_SQL_INTEGER" variable="nTypeOut" value="#nTypeOut#" null="No"> 
 </cfstoredproc>

 <cfdump var="#nTypeIn#">
 <cfdump var="#nTypeOut#">

In Oracle at the end of this test nTypeIn will be 10 but nTypeOut will be 100 not 10. That can be very useful as long as you are expecting the database stored proc to change it.

Hope that sheds a bit more light on the question.

仅一夜美梦 2024-08-26 17:35:37

来自维基百科:(

计算)与值关联的变量,因此是具有分配的存储位置的变量。如果编程语言实现规范的未知值、无穷大等的表示。 ,绑定到变量的值可能是其中之一。

请注意粗体部分

未绑定到位置的变量称为自由变量。

From wikipedia:

(computing) A variable that is associated with a value, and therefore a variable that has an allocated storage location. If the programming language implements a representation of a canonical unknown value, infinity, etc., the value bound to the variable may be one of these.

Notice the bold portion

Variables that are not bound to a location are known as free variables.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文