Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I issue a single command from the command line through sql plus?

Using SQL Plus, you can run a script with the "@" operator from the command line, as in:

c:\>sqlplus username/password@databasename @"c:\my_script.sql" 

But is it possible to just run a single command with a similar syntax, without a whole separate script file? As in:

c:\>sqlplus username/password@databasename @execute some_procedure 

I am interested in this because I want to write a batch file that simply executes a command, without generating a bunch of two-line ".sql" files.

like image 906
JosephStyons Avatar asked Mar 12 '09 13:03

JosephStyons


People also ask

How do I run a SQL statement from the command line?

Open a Command Prompt window, and type sqlcmd -SmyServer\instanceName. Replace myServer\instanceName with the name of the computer and the instance of SQL Server that you want to connect to. Press ENTER. The sqlcmd prompt (1>) indicates that you are connected to the specified instance of SQL Server.

What is SQL*Plus command?

SQL*Plus is a command-line tool that provides access to the Oracle RDBMS. SQL*Plus enables you to: Enter SQL*Plus commands to configure the SQL*Plus environment. Startup and shutdown an Oracle database. Connect to an Oracle database.

What is command line in SQL?

Oracle SQL Developer Command Line (SQLcl) is a free command line interface for Oracle Database. It allows you to interactively or batch execute SQL and PL/SQL.


2 Answers

I'm able to run an SQL query by piping it to SQL*Plus:

@echo select count(*) from table; | sqlplus username/password@database 

Give

@echo execute some_procedure | sqlplus username/password@databasename 

a try.

like image 127
Patrick Cuff Avatar answered Sep 21 '22 23:09

Patrick Cuff


Have you tried something like this?

sqlplus username/password@database < "EXECUTE some_proc /" 

Seems like in UNIX you can do:

sqlplus username/password@database <<EOF EXECUTE some_proc; EXIT; EOF 

But I'm not sure what the windows equivalent of that would be.

like image 31
Eric Petroelje Avatar answered Sep 19 '22 23:09

Eric Petroelje