Execute Oracle SQLs from Linux Command Prompt and Exit

advertisements

_____________________________________________________________________________________________________________________

The Eucharistic Miracles of the World
Method 1 

Execute single SQL command from the prompt







[oracle@TESTBOX exp]$ echo 'select count(*) from tab;' | sqlplus / as sysdba

SQL*Plus: Release 19.0.0.0.0 - Production on Fri Jul 17 07:46:47 2020
Version 19.3.0.0.0

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


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

SQL> 
  COUNT(*)
----------
      8308

SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0
advertisements
 
Method 2 
Execute multiple SQL statements using .sql script

$ cat test.sql
select 1 from dual;
select name from v$database; 
select count(*) from tab;

sqlplus / as sysdba @test.sql
sqlplus test/test @test.sql

To exit from the sql prompt either you have to put exit in the .sql file or use below command.

exit | sqlplus / as sysdba @test.sql

Demo:-


$ exit | sqlplus / as sysdba @test.sql

SQL*Plus: Release 19.0.0.0.0 - Production on Fri Jul 17 07:54:56 2020
Version 19.3.0.0.0

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


Connected to:
Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0


	 1
----------
	 1


NAME
---------
CDB


  COUNT(*)
----------
      8308

SQL> Disconnected from Oracle Database 19c Enterprise Edition Release 19.0.0.0.0 - Production
Version 19.3.0.0.0

Method 3

sqlplus /nolog <<EOF
connect test/test
@ test.sql 
select * from dual;
EOF

_____________________________________________________________________________________________________________________

Website Stats

0 comments:

Post a Comment

Labels

Oracle (629) Script (86) General (77) Unix (47) Blog (23) Technology (19) gadget (6) games (6) Business (3) OCI (3) SQL* Loader (3) Datapump (2)
 

acehints.com Copyright 2011-23 All Rights Reserved | Site Map | Contact | Disclaimer