The BIND_VARIABLE stored procedure binds a value to a variable. Each call to BIND_VARIABLE binds one value to one variable. You can call this procedure multiple times to bind multiple variables.
Variables in DBMS_SQL statements have names. Therefore, BIND_VARIABLE uses the variable name to bind a value to it.
Applicability
This topic applies only to OceanBase Database Enterprise Edition. OceanBase Database Community Edition provides only the MySQL mode.
Syntax
DBMS_SQL.BIND_VARIABLE(cursor_id IN INTEGER,
name IN VARCHAR2,
value IN NUMBER);
DBMS_SQL.BIND_VARIABLE(cursor_id IN INTEGER,
name IN VARCHAR2,
value IN VARCHAR2);
Parameters
| Parameter | Description |
|---|---|
| cursor_id | The ID of the cursor to which you want to bind a value. |
| name | The name of the variable in the statement. |
| value | The value that you want to bind to the variable in the cursor. |
Considerations
If the variable is an IN variable, an IN/OUT variable, or an IN collection, the value specified must be valid for the variable type. The bind value for an OUT variable is ignored.
Variables in SQL statements are identified by their names. When you bind a value to a variable, the string that identifies the variable in a statement must be preceded by a colon, as shown in the example below:
SELECT name FROM friend WHERE age > :X;
For this example, two possible variable binding calls are:
BIND_VARIABLE(cursor_name, ':X', 25);
and
BIND_VARIABLE (cursor_name, 'X', 25);