ORACLE_PATH
or SQLPATH
SELECT DEPARTMENT_ID, CITY FROM EMP_DETAILS_VIEW WHERE SALARY>12000; @subScript1.sql @@ subScript2.sql
select NAME from V\$PARAMETER where NAME like 'log_archive_dest_state_%';
" | sqlplus -s / as sysdba$
of V$PARAMETER
is escaped to avoid Bash parameter substitution.NAME -------------------------------------------------------------------------------- log_archive_dest_state_1 log_archive_dest_state_11 NAME -------------------------------------------------------------------------------- log_archive_dest_state_12 log_archive_dest_state_22 NAME -------------------------------------------------------------------------------- log_archive_dest_state_23 log_archive_dest_state_31 31 rows selected.
Just use the -s command line flag :
SQL*Plus: Release 11.2.0.3.0 Production on Tue Jul 5 12:53:45 2016 Copyright (c) 1982, 2011, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production With the Partitioning option SQL> SP2-0734: unknown command beginning "who is a c..." - rest of line ignored. SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production With the Partitioning option
SP2-0734: unknown command beginning "who is a c..." - rest of line ignored.
SELECT TO_CHAR(SYSDATE, 'MM-DD-YYYY HH24:MI:SS') \"NOW\" FROM DUAL;
" | sqlplus -s / as sysdbaNOW ---------------------------------------------------------------------------- 07-05-2016 13:00:09
;
and /
after each query) led to weird results such as executing each query twice./
after every query, including the last one;
in queriesquery1 / query2 / query3 /
;
in queriesexport ORACLE_SID=myOracleSid; sqlplus '/ as sysdba' << EOSQL query1; query2; query3; EOSQL
SQL> define _editor=vi
Or, as oracle : echo define _editor=vi >> $ORACLE_HOME/sqlplus/admin/glogin.sql
Then, should you make a typo or any kind of error in a command you type in SQL*Plus :select name from v$contrlofile * ERROR at line 1: ORA-00942: table or view does not exist
"afiedt.buf" 2 lines, 33 characters written
1* select name from v$controlfile
1* select name from v$controlfile NAME -------------------------------------------------------------------------------- /u01/app/oracle/oradata/MYDB/control01.ctl
SELECT TO_CHAR(SYSDATE, 'MM-DD-YYYY HH24:MI:SS') "NOW" FROM DUAL;
NOW ---------------------------------------------------------------------------- 07-07-2016 11:09:41
select * from dual;
D - X
For a (so far) unknown reason, query results returned by SQL*Plus are sometimes ugly / difficult to read because of the columns width which are WAY too large to fit the screen, resulting in wrapping lines. This is not convenient at all for tabular data
To fix this, use SQL*Plus's COLUMN.
Example :
export ORACLE_SID=ORACLE_SID; sqlplus '/ as sysdba' << EOSQL COLUMN process format a10; COLUMN status format a15; SELECT process, status, thread#, sequence#, delay_mins from V\$MANAGED_STANDBY; EOSQL
COLUMN process format a10;
means "display the process column 10 characters wide".
In this example, the $
is \
-escaped because the whole command is executed from the *Nix shell and we don't want expressions such as V$MANAGED_STANDBY
to be expanded by the shell.
COLUMN has MANY more interesting features, read more and view examples in SQL*Plus COLUMN FORMAT tips .
Such formatting is for reporting purposes only : it allows displaying a string n characters wide if we like it so whatever its width is defined in the table. COLUMN does not alter data or tables.