Home > Application Builder Concepts > Managing Session State Values > About Bind Variable Syntax
You can use bind variables syntax anywhere in Oracle Application Express where you are using SQL or PL/SQL to reference session state of a specified item. For example:
SELECT * FROM employees WHERE last_name like '%' || :SEARCH_STRING || '%'
In this example, the search string is a page item. If the region type is defined as SQL Query, you can reference the value using standard SQL bind variable syntax. Using bind variables ensures that parsed representations of SQL queries are reused by the database, optimizing memory usage by the server.
When using bind variable syntax, remember the following rules:
Bind variable names must correspond to an item name.
Bind variable names are not case-sensitive.
Bind variable names cannot be longer than 30 characters (that is, they must be a valid Oracle identifier).
Although page item and application item names can be up to 255 characters, if you intend to use an application item within SQL using bind variable syntax, the item name must be 30 characters or less.
If your region type is defined as a SQL Query, SQL Query (plsql function body returning SQL query), or list of values (LOV), you can reference session state using the following syntax:
:MY_ITEM
One common way to do this is to incorporate a session state variable in a WHERE
clause. The following example shows how to bind the value of the item THE_DEPTNO
into a region defined from a SQL Query.
SELECT last_name, job_id, salary FROM employees WHERE department_id = :THE_DEPTNO
For region types defined as a PL/SQL Procedure, regions are constructed using PL/SQL anonymous block syntax. In other words, the beginning and ending keywords are used to enclose the PL/SQL block. For example:
IF
:P1_JOB IS NOT NULL THEN INSERT INTO employees (employee_id, first_name, job_id) VALUES (:P1_EMP_ID
, :P1_NAME, :P1_JOB) end if;
In this example, the values of the employee_id
, first_name
, and job_id
are populated by the values of P1_EMP_ID
, P1_NAME
, and P1_JOB
.