Skip to content
Advertisement

LOOP/FOR statement on oracle script

I’m running an ansible playbook that runs an sqlplus script to an Oracle DB.
Basically the script creates a CSV file with some server info. The query is pretty much autogenerated, so it will be difficult change it.

The problem is that this query brings all the 5000 server and I need only 200.
I want to add a LOOP/FOR statement with only the servers I need, but I think I’m doing something wrong.
This is the query with the LOOP:

When I run it I get this error:

Error report –
ORA-06550: line 9, column 5:
PLS-00428: an INTO clause is expected in this SELECT statement
06550. 00000 – “line %s, column %s:n%s”
*Cause: Usually a PL/SQL compilation error.
*Action:

Sadly, I’m not much of a DBA and my knowledge got me so far. So suggestion will be appreciated

Advertisement

Answer

You can not use plain select sql without into clause like this in PL/SQL.

What are you expecting out of the query in PL/SQL?

Your first query executed and filled csv because it is single query and not anonymous block.

You can simply add condition into where clause of your first query as follows:

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement