PL/SQL 中的 IN、OUT、IN OUT 参数到底是什么
What exactly are IN, OUT, IN OUT parameters in PL/SQL
我已经在这里查过问题,也看过在线和观看视频,但我仍然对 IN、OUT 到底是什么感到困惑。我问的原因是因为我正在编写一个程序,该程序将根据其他程序中的 IN 参数记录错误,
干杯!
Oracle 文档 here 很好地解释了:
The mode of a parameter indicates whether the parameter passes data to a procedure (IN
), returns data from a procedure (OUT
), or can do both (IN OUT
).
以及关于OUT
参数的具体:
... you cannot use it to pass a value to the procedure. Nor can you read its value inside the procedure, even after a value has been assigned to it.
编辑
实际上,尽管上面提供的信息是有效的,但我链接到的资源很差(SQL*Ada 程序员指南模块)。
可以在此处找到更好、更完整的资源以更好地理解这 3 种模式:Table 8-1 PL/SQL Subprogram Parameter Modes。
IN
模式:
Default mode
Passes a value to the subprogram.
Formal parameter acts like a constant: When the subprogram begins, its value is that of either its actual parameter or default value, and the subprogram cannot change this value.
Actual parameter can be a constant, initialized variable, literal, or expression.
Actual parameter is passed by reference.
OUT
模式:
Must be specified.
Returns a value to the invoker.
Formal parameter is initialized to the default value of its type. The default value of the type is NULL
except for a record type with a non-NULL
default value.
When the subprogram begins, the formal parameter has its initial value regardless of the value of its actual parameter. Oracle recommends that the subprogram assign a value to the formal parameter.
If the default value of the formal parameter type is NULL
, then the actual parameter must be a variable whose data type is not defined as NOT NULL
.
By default, actual parameter is passed by value; if you specify NOCOPY
, it might be passed by reference.
IN OUT
模式:
Must be specified.
Passes an initial value to the subprogram and returns an updated value to the invoker.
Formal parameter acts like an initialized variable: When the subprogram begins, its value is that of its actual parameter. Oracle recommends that the subprogram update its value.
Actual parameter must be a variable (typically, it is a string buffer or numeric accumulator).
By default, actual parameter is passed by value (in both directions); if you specify NOCOPY
, it might be passed by reference.
我已经在这里查过问题,也看过在线和观看视频,但我仍然对 IN、OUT 到底是什么感到困惑。我问的原因是因为我正在编写一个程序,该程序将根据其他程序中的 IN 参数记录错误,
干杯!
Oracle 文档 here 很好地解释了:
The mode of a parameter indicates whether the parameter passes data to a procedure (
IN
), returns data from a procedure (OUT
), or can do both (IN OUT
).
以及关于OUT
参数的具体:
... you cannot use it to pass a value to the procedure. Nor can you read its value inside the procedure, even after a value has been assigned to it.
编辑
实际上,尽管上面提供的信息是有效的,但我链接到的资源很差(SQL*Ada 程序员指南模块)。
可以在此处找到更好、更完整的资源以更好地理解这 3 种模式:Table 8-1 PL/SQL Subprogram Parameter Modes。
IN
模式:
Default mode
Passes a value to the subprogram.
Formal parameter acts like a constant: When the subprogram begins, its value is that of either its actual parameter or default value, and the subprogram cannot change this value.
Actual parameter can be a constant, initialized variable, literal, or expression.
Actual parameter is passed by reference.
OUT
模式:
Must be specified.
Returns a value to the invoker.
Formal parameter is initialized to the default value of its type. The default value of the type is
NULL
except for a record type with a non-NULL
default value.When the subprogram begins, the formal parameter has its initial value regardless of the value of its actual parameter. Oracle recommends that the subprogram assign a value to the formal parameter.
If the default value of the formal parameter type is
NULL
, then the actual parameter must be a variable whose data type is not defined asNOT NULL
.By default, actual parameter is passed by value; if you specify
NOCOPY
, it might be passed by reference.
IN OUT
模式:
Must be specified.
Passes an initial value to the subprogram and returns an updated value to the invoker.
Formal parameter acts like an initialized variable: When the subprogram begins, its value is that of its actual parameter. Oracle recommends that the subprogram update its value.
Actual parameter must be a variable (typically, it is a string buffer or numeric accumulator).
By default, actual parameter is passed by value (in both directions); if you specify
NOCOPY
, it might be passed by reference.