-
Notifications
You must be signed in to change notification settings - Fork 126
/
getbinds-sqlid.sql
82 lines (70 loc) · 2.48 KB
/
getbinds-sqlid.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
PROMPT
PROMPT~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
PROMPT------ /) (\
PROMPT------ .-._((,~~.))_.-,
PROMPT------ `-. @@ ,-'
PROMPT------ / ,o--o. \
PROMPT------ ( ( .__. ) )
PROMPT------ ) `----' (
PROMPT------ / \
PROMPT------ / \
PROMPT------ / \
PROMPT------ "The Silly Cow"
PROMPT----- Script: getbinds-sqlid.sql
PROMPT----- Author: Prashant 'The FatDBA'
PROMPT----- Version: V1.1 (Date: 04-02-2015)
PROMPT-----
PROMPT-----
PROMPT-----
col username format a15
col sid format 9999
col datatype_string format a15 head 'DATA TYPE'
col child_nume format 999999 head 'CHILD|NUMBER'
col position format 999 head 'POS'
col name format a20
col value_string format a40
col bind_string format a40
col type_name format a15
set line 200
col u_sql_id new_value u_sql_id noprint
set term on feed on echo off pause off verify off
prompt Which SQL_ID? :
set term off feed off
select '&1' u_sql_id from dual;
set term on feed on
var v_sql_id varchar2(30)
exec :v_sql_id := '&u_sql_id'
break on inst_id on child_address on child_number on plan_hash_value
with plans as (
select distinct inst_id, address, sql_id, child_address, child_number, plan_hash_value
from gv$sql_plan
where sql_id = :v_sql_id
)
select
b.inst_id
, b.child_address
, b.child_number
, p.plan_hash_value
, b.position
, b.name
, b.value_string
, anydata.GETTYPENAME(b.value_anydata) type_name
-- use the anydata values as they are sometimes more reliable dependent on oracle version
, case anydata.GETTYPENAME(b.value_anydata)
when 'SYS.VARCHAR' then anydata.accessvarchar(b.value_anydata)
when 'SYS.VARCHAR2' then anydata.accessvarchar2(b.value_anydata)
when 'SYS.CHAR' then anydata.accesschar(b.value_anydata)
when 'SYS.DATE' then to_char(anydata.accessdate(b.value_anydata),'yyyy-mm-dd hh24:mi:ss')
when 'SYS.TIMESTAMP' then to_char(anydata.accesstimestamp(b.value_anydata),'yyyy-mm-dd hh24:mi:ss')
when 'SYS.NUMBER' then to_char(anydata.accessnumber(b.value_anydata))
end bind_string
from GV$SQL_BIND_CAPTURE b
join plans p on p.address = b.address
and p.inst_id = b.inst_id
and p.sql_id = b.sql_id
and p.child_address = b.child_address
and p.child_number = b.child_number
where b.sql_id = :v_sql_id
order by b.inst_id, b.child_address, b.child_number, b.position
/
undef 1