# ORA-00900: invalid SQL statement

**URL:** <https://forums.toadworld.com/t/ora-00900-invalid-sql-statement/49017>\
**Category:** Toad for Oracle & DevOps Toolkit\
**Created:** [February 12, 2020, 6:07am UTC](https://forums.toadworld.com/t/ora-00900-invalid-sql-statement/49017 "2020-02-12T06:07:06Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![antoine\_mc1](https://avatars.discourse-cdn.com/v4/letter/a/d07c76/32.png) [@antoine\_mc1](https://forums.toadworld.com/u/antoine_mc1)\
**Post date:** [February 12, 2020, 6:07am UTC](https://forums.toadworld.com/t/ora-00900-invalid-sql-statement/49017/1 "2020-02-12T06:07:06Z")

</div>

Hello,  
Is it possible anonymous block?

DECLARE  
CURSOR CUR IS  
SELECT FIRST\_NAME || JOB\_ID || HIRE\_DATE AS RS FROM HR.EMPLOYEES;  
BEGIN  
FOR I IN CUR LOOP  
EXECUTE IMMEDIATE I.RS;  
END LOOP;  
END;

Thanks for your advice

---

<div class="post-metadata">

**Author:** ![Gary.Jerep](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/gary.jerep/32/205_2.png) [@Gary.Jerep](https://forums.toadworld.com/u/Gary.Jerep)\
**Post date:** [February 12, 2020, 5:24pm UTC](https://forums.toadworld.com/t/ora-00900-invalid-sql-statement/49017/2 "2020-02-12T17:24:12Z")

</div>

If you're asking if Toad/Oracle can execute anonymous blocks, then answer is yes.

If you're asking advice on coding, this is the wrong forum. That said, I don't think you're code above will work, for a number of reasons, even though I'm not a PL/SQL expert.

Here's a link with examples to get you started... there's tons of other stuff on the net you can dig up:  
[https://docs.oracle.com/cd/B19306\_01/appdev.102/b14261/dynamic.htm](https://docs.oracle.com/cd/B19306_01/appdev.102/b14261/dynamic.htm)

Hope this helps.

---

<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:** [February 12, 2020, 5:37pm UTC](https://forums.toadworld.com/t/ora-00900-invalid-sql-statement/49017/3 "2020-02-12T17:37:58Z")

</div>

The reason that your pl/sql block fails is because your cursor loop is selecting some values out of the HR.EMPLOYEES table, and then trying to run those values as a sql statement.

I'm not really sure what you intended for that code to do, but either of these runs without error:

```
DECLARE
  CURSOR CUR IS
    SELECT FIRST_NAME || JOB_ID || HIRE_DATE AS RS FROM HR.EMPLOYEES;
BEGIN
  FOR I IN CUR LOOP
    dbms_output.put_line(I.RS);
  END LOOP;
END;

BEGIN
  EXECUTE IMMEDIATE 'SELECT FIRST_NAME || JOB_ID || HIRE_DATE AS RS FROM HR.EMPLOYEES';
END;
```

---

<div class="post-metadata">

**Author:** ![Abraham\_Olsen](https://avatars.discourse-cdn.com/v4/letter/a/57b2e6/32.png) [@Abraham\_Olsen](https://forums.toadworld.com/u/Abraham_Olsen)\
**Post date:** [February 18, 2020, 10:20am UTC](https://forums.toadworld.com/t/ora-00900-invalid-sql-statement/49017/4 "2020-02-18T10:20:02Z")

</div>

execute immediate will execute any valid statement (SQL or PL/SQL).  
Error message is your best friend, in term of what might go wrong.  
Try to run the output of the cursor in any application (Toad, SQL-Developer, sqlplus...) and the error message will be the same.  
The statement, that the code is running, is something like "SMITH 11 17-DEC-80" which is not a SQL statement. 00900 is the only response expected.

---

<div class="post-metadata">

**Author:** ![teresa.bauer-morriso](https://avatars.discourse-cdn.com/v4/letter/t/9e8a1a/32.png) [@teresa.bauer-morriso](https://forums.toadworld.com/u/teresa.bauer-morriso)\
**Post date:** [April 9, 2020, 5:14pm UTC](https://forums.toadworld.com/t/ora-00900-invalid-sql-statement/49017/5 "2020-04-09T17:14:41Z")

</div>

New to the forum and not sure if this is how to post but here it goes.  
A user is getting the ORA-00900 invalid SQL statement in Toad for Oracle 12.9 64 bit. This is a recent install. The code is as follows. Others that run this same code with the same version of Toad for Oracle do not get the error.

select  
INBND\_ACCT\_NBR ,  
CUSTMR\_NBR ,  
CUSTMR\_BILL\_GRP\_ID ,  
SRC\_CD ,  
AMT\_PD ,  
RECRD\_INSERT\_DT ,  
SRC\_NM ,  
FILE\_DT ,  
EFF\_DT ,  
TRANSACT\_ID ,  
FILE\_POOL\_ID ,  
COUNTRY\_CD ,  
RETURN\_CD ,  
CHK\_NBR ,  
PMT\_TYPE ,  
ACCT\_COUNTRY\_CD ,  
SYSTEM\_OF\_RECRD ,  
PARTIAL\_ACCT\_NBR ,  
TRANSACT\_ACCT\_NBR ,  
ACCT\_NBR ,  
SENT\_STATUS,  
SENT\_FILE\_DT

FROM MART\_FINC. PMT\_GW\_DATA\_RPT  
--WHERE --FILE\_DT between '20190712' and '20190715'  
WHERE FILE\_DT = '20190108'  
AND src\_cd like '%LBCP%' ---UWQC'---CANP', 'CASP', 'CANR', 'CASR'2  
--WHERE PARTIAL\_ACCT\_NBR like '%112005549670%'  
--and AMT\_PD = '301.10'  
AND COUNTRY\_CD ='US'  
AND FILE\_POOL\_ID LIKE '%0256'

Please help!

---

<div class="post-metadata">

**Author:** ![NormTeamT](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/normteamt/32/53_2.png) [@NormTeamT](https://forums.toadworld.com/u/NormTeamT)\
**Post date:** [April 9, 2020, 7:24pm UTC](https://forums.toadworld.com/t/ora-00900-invalid-sql-statement/49017/6 "2020-04-09T19:24:54Z")

</div>

I suspect it's because you have a blank line and no semicolon. Possibly.

I know Sql\*plus does not like blanks at all, Toad doesn't mind, but:

If you have two statements, and no semicolon, then they need to be separated by a blank line.

I think what's happening here is that your trying to F9 (execute) the second part of the SQL - where is the caret when the error occurs - and the Toad parser thinks you have two statements, the second of which starts at `FROM MART_FINC` which is indeed invalid.

Sorry if I sound vague, I'm not near a database or my Toad, and I always use semicolons. 😉

HTH

Cheers,  
Norm. [TeamT]

---

<div class="post-metadata">

**Author:** ![NormTeamT](https://sea1.discourse-cdn.com/quest/user_avatar/forums.toadworld.com/normteamt/32/53_2.png) [@NormTeamT](https://forums.toadworld.com/u/NormTeamT)\
**Post date:** [April 9, 2020, 7:29pm UTC](https://forums.toadworld.com/t/ora-00900-invalid-sql-statement/49017/7 "2020-04-09T19:29:47Z")

</div>

PS. This:

`WHERE FILE_DT = '20190108'`

_should be_:

`WHERE FILE_DT = to_date('20190108', 'yyyymmdd')`

If FILE\_DT is a DATE data type. If there is an index on the column, using a string literal as in your example, will prevent the index being used.

If, on the other hand, it is a VARCHAR2 column, I'm afraid you need to go and have a word with the data designer and convince him/her to use the correct data types. 😉

Cheers,  
Norm. [TeamT]
