Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to pass a single query to SQLplus?

I regularly need to run a single query on some table in one of my DBs and I would rather not have to create a file and call it as a script and everything if I don't have to.

I would like to be able to send the query directly to sqlplus as a string like this perhaps

sqlplus user/pass@hostname:port/service "select * from table"

instead of having to create a file that holds only that one query and call it with

sqlplus user/pass@hostname:port/service @filename

does anyone know if this is possible?

like image 318
Samuel Owens Avatar asked Dec 20 '25 08:12

Samuel Owens


1 Answers

In addition to mathguy answer, with linux shells, you can use the operator here-string like this:

sqlplus user/pass@hostname:port/service <<< 'select * from table;'

Don't forget the semi-colon at the end of your query.

like image 187
Stéphane Millien Avatar answered Dec 22 '25 22:12

Stéphane Millien



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!