Search notes:

Oracle SQL: Bind variables

Selecting bound values with dynamic performance views

create or replace procedure tq84_test_bind(p1 number, p2 varchar2, p3 date) as
   cnt number;
begin
   select /* find-me */ count(*) into cnt from dual where 42 = p1 and 'hello world' = p2 and sysdate = p3;
end tq84_test_bind;
/
exec tq84_test_bind(42, 'hello world', sysdate);
select
   sql.sql_id,
   to_char(cap.last_captured, 'yyyy-mm-dd hh24:mi:ss') last_captured,
   any_value(case when met.position =  1 then cap.value_string end) bind_01,
   any_value(case when met.position =  2 then cap.value_string end) bind_02,
   any_value(case when met.position =  3 then cap.value_string end) bind_03,
   any_value(case when met.position =  4 then cap.value_string end) bind_04,
   any_value(case when met.position =  5 then cap.value_string end) bind_05,
   any_value(case when met.position =  6 then cap.value_string end) bind_06,
   any_value(case when met.position =  7 then cap.value_string end) bind_07,
   any_value(case when met.position =  8 then cap.value_string end) bind_08,
   any_value(case when met.position =  9 then cap.value_string end) bind_09,
   any_value(case when met.position = 10 then cap.value_string end) bind_10,
   any_value(case when met.position = 11 then cap.value_string end) bind_11,
   any_value(case when met.position = 12 then cap.value_string end) bind_12,
   any_value(case when met.position = 13 then cap.value_string end) bind_13,
   any_value(case when met.position = 14 then cap.value_string end) bind_14,
   any_value(case when met.position = 15 then cap.value_string end) bind_15,
   any_value(case when met.position = 16 then cap.value_string end) bind_16,
   any_value(case when met.position = 17 then cap.value_string end) bind_17,
   any_value(case when met.position = 18 then cap.value_string end) bind_18,
   any_value(case when met.position = 19 then cap.value_string end) bind_19,
   sql.sql_text
from
   v$sql_bind_capture  cap                                             join
   v$sql_bind_metadata met on cap.child_address = met.address    and   
                              cap.position      = met.position         join
   v$sql               sql on cap.child_address = sql.child_address
where
   sql.sql_text like q'[SELECT COUNT(*) FROM DUAL WHERE 42 = :B3 AND 'hello world' = :B2 AND SYSDATE = :B1%]'
group by
   sql.sql_id,
   sql.sql_text,
   cap.last_captured;

See also

Bind variables cannot be used in DDL statements (ORA-01027: bind variables not allowed for data definition operations)
The init parameters
The SQL*Plus statement variable declares a bind variable.
explain plan assumes bind variables to be a varchar2 data type, see this caveat.
Adaptive cursor sharing allows to create multiple execution plans for a statement that has bind variables (where these execution plans adapt to the values of the bind variables at execution time).
Bind variable values are stored in the private SQL area
Error messages such as
Bind variable in SQL*Plus
dbms_sql.bind_variable
dba_hist_sqlbind, dba_hist_sql_bind_metadata, dba_sqlset_binds, dba_sqltune_binds
v$sql_bind_data, v$sql_bind_metadata, v$sql_bind_capture
The PL/SQL type sys.sql_bind
PGA
The persistent area of the private SQL area.
A table macro allows to parametrize a select statement with a PL/SQL function at the places where bind variables are also allowed.
x$kksbv, x$kqlfbc, x$kxsbd
The ADO object parameter

Links

Jonathan Lewis notes that histograms and bind variables exist for diametrically opposed reasons.

Index

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1758191571, '216.73.216.150', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/databases/Oracle/SQL/statement/bind-variables/index(142): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78