Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make a sqlplus quit when database is not available?

Tags:

oracle

sqlplus

i have a problem with sqlplus on windows batch. I have SQLPLUS 10.2

i'm trying to connect to a database through a windows script.cmd

script.cmd only launches : sqlplus test/Test@mydatabase @script.sql

The problem is when the database is not available, the sqlplus says

ERROR:
ORA-12541: TNS:no listener
Enter user-name : 

and waits for input .. and blocks the .cmd

How can i adapt the script to stop immediately when the database is not avaliable or just to avoid waiting for user prompts ?

Thanks

like image 632
Fredv Avatar asked Jul 04 '11 06:07

Fredv


People also ask

How do I stop SQL Plus?

To exit SQL*Plus command-line, enter EXIT. To exit the Windows GUI, enter EXIT or select Exit from the File menu.

How do you end a SQL statement?

You can end a SQL command in one of three ways: with a semicolon (;) with a slash (/) on a line by itself. with a blank line.

What does set define off do?

The SET DEFINE command changes the prefix character used to mark substitution variables. You can use SET DEFINE to turn variable substitution off.


1 Answers

You can do sqlplus -l test/Test@mydatabase @script.sql; the -l flag means it will only try to connect once, and if it fails for any reason will exit instead of prompting. Look at the output of sqlplus -?, or see the documentation.

like image 110
Alex Poole Avatar answered Nov 23 '22 08:11

Alex Poole