• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 312
  • Last Modified:

how to create a batch of sql in oracle?

I have several select statements and two delete statements, I want to run as a batch, no need to run one by one.

Here is my batch,


select * from A where ID=2;
select * from B where ID=2;
Delete from A where ID=2;
Delete from B where ID=2

But, it doesn't work, what is wrong with it?

1 Solution
slightwv (䄆 Netminder) Commented:
Begin and end signify a pl/sql block.

You cannot select in pl/sql without selecting into something.

You can remove the begin/end and run this as a sqlplus script.  What exactly are you wanting to do with the output of the select before the deletes?

If you only want to run all those sql commands from one single command, all you have to do is put them in a file and call that file from sqlplus.

To call a file from sqlplus, you use '@' like this :


sqlplus / as sysdba
SQL>@/path/to /your/file.txt


If your file is a '.sql' you can call it even without the extension (I don't know if this works also for windows though, but sure for any *nix) :

@/path/to /your/file

Only make sure your file is a text file.


If you want to connect to sqlplus AND call the file from a single line (I don't know if this works also for windows though, but sure for any *nix) :

sqlplus "/ as sysdba" @file.sql

You put the right user/password in the connection string. And make sure you close the session : add an 'exit' command at the end of your file.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now