2

In SQL*Plus, I want to execute multiple SQL queries in single line like

create table emp(name varchar2(20)); desc emp;

I tried executing this one but didn't work for me.

BEGIN OPEN :1 FOR SELECT * FROM table1; OPEN :2 FOR SELECT * FROM table2; END;

is there any way to accomplish this?

Thanks in advance!

3
  • what are :1 and :2 ?. Why do u use bind variables for them? Commented Sep 13, 2017 at 11:21
  • desc emp is NOT a SQL query, it is a SQL*Plus command (which SQL*Plus translates, behind the scenes - invisible to you! - into an actual SQL query against several data dictionary tables). Technically there should be no semicolon after desc emp although SQL*Plus may be flexible and not throw an error. Then, your second line of code is not a SQL query either, it is a PL/SQL block. It seems that you have very, very basic understanding issues; go back to the first 15-20 pages of your textbook and re-read about SQL vs. PL/SQL vs. SQL*Plus, they are very different things. Commented Sep 13, 2017 at 14:11
  • @mathguy what if I want to execute insert into emp (name) values('Foo') and 'select * from emp` in a single line is this possible? Thanks in advance :D Commented Sep 15, 2017 at 9:00

1 Answer 1

3

SQL*Plus expects either:

  • A single SQL command, terminated by either a ";" character or a "/" on a line by itself.
  • A PL/SQL block
  • A SQL*Plus command

What you have entered is 2 queries on a single line, which SQL*Plus will send to the RDBMS - Oracle will then try and parse the string sent as a single query and fail because it is not valid SQL.

A quick workaround would be to have all your commands in a sql file and run them using @file.sql

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.