Skip to Main Content
  • Questions
  • commands execution sequence of sqlplus

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, kevin.

Asked: October 22, 2016 - 2:08 am UTC

Last updated: October 22, 2016 - 8:42 am UTC

Version: 10.2.0.5

Viewed 1000+ times

You Asked

dear Tom,
I have command
echo "exit" | sqlplus $CONDB @LONGSQL
in AIX. Questions:
1. will sqlplus always execute exit after executing LONGSQL.
2. If there is no exit in LONGSQL,what is the better way to let sqlplus exit after executing LONGSQL in AIX.

and Connor said...

That looks ok to me...

[oracle@host122 ~]$ cat test.sh
echo "exit" | sqlplus / as sysdba @test.sql
[oracle@host122 ~]$ cat test.sql
select 'RUNNING_TEST' from dual;

[oracle@host122 ~]$ ./test.sh

SQL*Plus: Release 12.2.0.1.0 Production on Sat Oct 22 09:37:50 2016

Copyright (c) 1982, 2016, Oracle.  All rights reserved.


Connected to:
Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production

/bin/bash: title: command not found


'RUNNING_TES
------------
RUNNING_TEST

sys@db122
SQL> Disconnected from Oracle Database 12c Enterprise Edition Release 12.2.0.1.0 - 64bit Production



And works if the username is wrong as well

[oracle@host122 ~]$ ./test.sh

SQL*Plus: Release 12.2.0.1.0 Production on Sat Oct 22 09:38:48 2016

Copyright (c) 1982, 2016, Oracle.  All rights reserved.

ERROR:
ORA-01017: invalid username/password; logon denied


Enter user-name: Enter password: 
ERROR:
ORA-01005: null password given; logon denied


Enter user-name: [oracle@host122 ~]$ 




One thing I normally do is put the connection string in the script itself rather than on the command line. (Some versions of SQL PLus will leave that visible from things like a 'ps' listing). So I do:

print "
connect u/p
@longsql
exit" | sqlplus /nolog





Is this answer out of date? If it is, please let us know via a Comment