# SQL error on script run in editor (bug)

**URL:** <https://forums.toadworld.com/t/sql-error-on-script-run-in-editor-bug/38537>\
**Category:** Toad for Oracle & DevOps Toolkit\
**Created:** [October 25, 2016, 12:48am UTC](https://forums.toadworld.com/t/sql-error-on-script-run-in-editor-bug/38537 "2016-10-25T00:48:12Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![damir.vadas\_250](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/damir.vadas_250/32/37_2.png) [@damir.vadas\_250](https://forums.toadworld.com/u/damir.vadas_250)\
**Post date:** [October 25, 2016, 12:48am UTC](https://forums.toadworld.com/t/sql-error-on-script-run-in-editor-bug/38537/1 "2016-10-25T00:48:12Z")

</div>

Toad 12.10.0.30 x64

Next sql is in script called sql\_binds and I call it inside Editor like:

"@sql\_binds 1 75undgc5qufbm 10"  
where call is made of:  
@sql\_binds [iid] [sql\_id] [last\_number\_of\_days]

I got error (and in sqlplus it run without any errors)

> > SELECT iid,  
> > b.sql\_id,  
> > PLAN\_HASH\_VALUE PLAN\_HASH\_V,  
> > b.name,  
> > b.position,  
> > '"'||value\_string||'"' value\_string,  
> > EXECS,  
> > A\_ROWS,  
> > ELA\_SECS,  
> > ELAPSED\_TIME\_TOTAL,  
> > snap\_id,  
> > to\_char (begin\_interval\_time, 'DD.MM hh24:mi:ss,ssss') begin\_interval\_time,  
> > to\_char (end\_interval\_time, 'hh24:mi:ss,ssss') end\_interval\_time  
> > FROM (  
> > SELECT sh.instance\_number iid,  
> > sql\_id,  
> > PLAN\_HASH\_VALUE,  
> > sh.snap\_id,  
> > begin\_interval\_time,  
> > end\_interval\_time,  
> > bind\_data,  
> > EXECUTIONS\_DELTA EXECS,  
> > ROWS\_PROCESSED\_DELTA A\_ROWS,  
> > CASE EXECUTIONS\_DELTA  
> > WHEN 0 THEN -1  
> > ELSE ELAPSED\_TIME\_DELTA/1000000/EXECUTIONS\_DELTA  
> > END ELA\_SECS,  
> > ELAPSED\_TIME\_TOTAL/1000000/60 ELAPSED\_TIME\_TOTAL  
> > FROM dba\_hist\_sqlstat sql, dba\_hist\_snapshot sh  
> > WHERE 1 = 1  
> > -- AND bind\_data is not null  
> > AND sql\_id = '75'  
> > AND sh.instance\_number=1  
> > AND SQL.INSTANCE\_NUMBER=sh.instance\_number  
> > AND SQL.SNAP\_ID = SH.SNAP\_ID  
> > AND begin\_interval\_time \>= sysdate - undgc5qufbm  
> > ) x,  
> > TABLE (DBMS\_SQLTUNE.extract\_binds (x.bind\_data)) xx,  
> > DBA\_HIST\_SQL\_BIND\_METADATA b  
> > where b.sql\_id = x.sql\_id  
> > AND b.position = xx.position  
> > ORDER BY iid, snap\_id, PLAN\_HASH\_VALUE, b.position

```
                                              *

```

Error at line 36  
ORA-00904: "UNDGC5QUFBM": invalid identifier  
Script Terminated on line 20 of u:\sql\sql\_binds.SQL.

What i see is that second parameter "75undgc5qufbm" is not passed correctly to sql. It is represented as  
AND sql\_id = **'75**'

so what results with wrong bind on third part  
AND begin\_interval\_time \>= sysdate - **undgc5qufbm**

I hope this helps and is enough to find a bug

---

<div class="post-metadata">

**Author:** ![Mark\_Kurtz](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/mark_kurtz/32/10_2.png) [@Mark\_Kurtz](https://forums.toadworld.com/u/Mark_Kurtz)\
**Post date:** [October 25, 2016, 7:56am UTC](https://forums.toadworld.com/t/sql-error-on-script-run-in-editor-bug/38537/2 "2016-10-25T07:56:56Z")

</div>

To me it looks like you are trying to subtract a string value (75undgc5qufbm) from sysdate. I am not sure how that would work since your string is not a numeric value.

Maybe you could provide more details about what this string represents?

-Mark

---

<div class="post-metadata">

**Author:** ![damir.vadas\_250](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/damir.vadas_250/32/37_2.png) [@damir.vadas\_250](https://forums.toadworld.com/u/damir.vadas_250)\
**Post date:** [October 25, 2016, 8:19am UTC](https://forums.toadworld.com/t/sql-error-on-script-run-in-editor-bug/38537/3 "2016-10-25T08:19:45Z")

</div>

No!

Toad misinterpreted pram values passed to script.

please look better in mine description

---

<div class="post-metadata">

**Author:** ![JohnDorlon](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/johndorlon/32/9997_2.png) [@JohnDorlon](https://forums.toadworld.com/u/JohnDorlon)\
**Post date:** [October 25, 2016, 8:27am UTC](https://forums.toadworld.com/t/sql-error-on-script-run-in-editor-bug/38537/4 "2016-10-25T08:27:03Z")

</div>

Did you try putting the string variables inside of quotes?

@sql\_binds 1 “75undgc5qufbm” 10

---

<div class="post-metadata">

**Author:** ![damir.vadas\_250](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/damir.vadas_250/32/37_2.png) [@damir.vadas\_250](https://forums.toadworld.com/u/damir.vadas_250)\
**Post date:** [October 25, 2016, 8:30am UTC](https://forums.toadworld.com/t/sql-error-on-script-run-in-editor-bug/38537/5 "2016-10-25T08:30:47Z")

</div>

Yes I did.  
No error but no result as well:

no rows selected.Elapsed: 00:00:00.07

Here is the whole script-parameters explained on the begining

col name for a10  
col VALUE\_STRING for a35  
col BEGIN\_INTERVAL\_TIME for a19 HEADING BEGIN\_INTERVAL  
col END\_INTERVAL\_TIME for a13 HEADING END\_INTERVAL  
col position for 90 HEADING POS  
col A\_ROWS HEADING ROWS  
col EXECS for 999G990  
col A\_ROWS for 999G990  
col ELA\_SECS for 99G990D9990  
col ELAPSED\_TIME\_TOTAL HEADING TOTAL\_MIN  
– col ELAPSED\_TIME\_HEADING DELTA ELA\_DELTA  
set pages 1000  
set linesize 180

break on iid on sql\_id on PLAN\_HASH\_VALUE on snap\_id on EXECS on A\_ROWS on ELA\_SECS on ELAPSED\_TIME\_TOTAL on begin\_interval\_time on end\_interval\_time

SELECT iid,  
b.sql\_id,  
PLAN\_HASH\_VALUE PLAN\_HASH\_V,  
b.name,  
b.position,  
‘"’||value\_string||’"’ value\_string,  
EXECS,  
A\_ROWS,  
ELA\_SECS,  
ELAPSED\_TIME\_TOTAL,  
snap\_id,  
to\_char (begin\_interval\_time, ‘DD.MM hh24:mi:ss,ssss’) begin\_interval\_time,  
to\_char (end\_interval\_time, ‘hh24:mi:ss,ssss’) end\_interval\_time  
FROM (  
SELECT /\*+ USE\_MERGE(sh,sql) ORDERED \*/  
sh.instance\_number iid,  
sql\_id,  
PLAN\_HASH\_VALUE,  
sh.snap\_id,  
begin\_interval\_time,  
end\_interval\_time,  
bind\_data,  
EXECUTIONS\_DELTA EXECS,  
ROWS\_PROCESSED\_DELTA A\_ROWS,  
CASE EXECUTIONS\_DELTA  
WHEN 0 THEN -1  
ELSE ELAPSED\_TIME\_DELTA/1000000/EXECUTIONS\_DELTA  
END ELA\_SECS,  
ELAPSED\_TIME\_TOTAL/1000000/60 ELAPSED\_TIME\_TOTAL  
FROM dba\_hist\_sqlstat sql, dba\_hist\_snapshot sh  
WHERE 1 = 1  
– AND bind\_data is not null  
AND sql\_id = ‘&&2’  
AND sh.instance\_number=&&1  
AND SQL.INSTANCE\_NUMBER=sh.instance\_number  
AND SQL.SNAP\_ID = SH.SNAP\_ID  
AND begin\_interval\_time \>= sysdate - &&3  
) x,  
TABLE (DBMS\_SQLTUNE.extract\_binds (x.bind\_data)) xx,  
DBA\_HIST\_SQL\_BIND\_METADATA b  
where b.sql\_id = x.sql\_id  
AND b.position = xx.position  
ORDER BY iid, snap\_id, PLAN\_HASH\_VALUE, b.position;

---

<div class="post-metadata">

**Author:** ![JohnDorlon](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/johndorlon/32/9997_2.png) [@JohnDorlon](https://forums.toadworld.com/u/JohnDorlon)\
**Post date:** [October 25, 2016, 8:36am UTC](https://forums.toadworld.com/t/sql-error-on-script-run-in-editor-bug/38537/6 "2016-10-25T08:36:35Z")

</div>

I got it to work with single quotes:

@sql\_binds 1 ‘75undgc5qufbm’ 10

---

<div class="post-metadata">

**Author:** ![damir.vadas\_250](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/damir.vadas_250/32/37_2.png) [@damir.vadas\_250](https://forums.toadworld.com/u/damir.vadas_250)\
**Post date:** [October 25, 2016, 8:39am UTC](https://forums.toadworld.com/t/sql-error-on-script-run-in-editor-bug/38537/7 "2016-10-25T08:39:05Z")

</div>

Thx-work.

But then this is different than SQLPlus parameters.

Any rule here to know for the future use?

---

<div class="post-metadata">

**Author:** ![JohnDorlon](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/johndorlon/32/9997_2.png) [@JohnDorlon](https://forums.toadworld.com/u/JohnDorlon)\
**Post date:** [October 25, 2016, 8:41am UTC](https://forums.toadworld.com/t/sql-error-on-script-run-in-editor-bug/38537/8 "2016-10-25T08:41:17Z")

</div>

That’s not my part of Toad - let’s wait for one of the other devs to answer.
