Professional Documents
Culture Documents
---------------------------------------------------------------------- ----------------------------------------------------------------------
Something's wrong with my CLOB/ NCLOB/ LONG column. Where is my How does one use the SQL*Plus utility?
data?
Start using SQL*Plus by executing the "sqlplus" command-line
SQL*Plus by default only shows the first 80 bytes of any LONG, utility from the $ORACLE_HOME/bin directory. Some of the command
CLOB and NCLOB datatypes. The data is there, but since sqlplus is line options:
a command-line tool it tries not to print out too much data. You
userid/password@db -- Connection details
can override this to tell sqlplus exactly how many bytes you want
/nolog -- Do not login to Oracle. You will need to do
to see:
-- it yourself.
SET LONG 32000 -s or -silent -- start sqlplus in silent mode. Not
SELECT text FROM user_views WHERE rownum = 1; -- recommended for beginners!
@myscript -- Start executing script called myscript.sql"
How does one copy data from one database to another in SQL*Plus?
sqlplus /nolog
SQL> connect scott/tiger
The SQL*Plus COPY command is one of the fastest ways of copying SQL> select * from tab;
data between databases and schemas. This is also one of the few SQL> disconnect
methods that will handle LONG columns correctly. Look at this SQL> exit
example:
COPY FROM SCOTT/TIGER@LOCAL_DB TO SCOTT/TIGER@REMOTE_DB - What commands can be executed from SQL*Plus?
CREATE IMAGE_TABLE USING -
SELECT IMAGE_NO, IMAGE -
One can enter three kinds of commands from the SQL*Plus command
FROM IMAGES;
prompt:
SQL*Plus commands
Can one generate HTML reports from SQL*Plus?
SQL*Plus commands are used to set options for SQL*Plus, format
reports, edit files, edit the command buffer, and so on. SQL*Plus
One can generate static HTML pages from SQL*Plus (8.1.6 and
commands do not interact with the database. These commands do not
above) by setting the MARKUP option to HTML ON. This can be done
have to be terminated with a semicolon (;) (as is the case with
by specifying -MARKUP "HTML ON" from command line, or with the
SQL commands). Examples:
"SET MARKUP HTML ON" command. Look at this example SQL Script:
SQL> CLEAR SCREEN
set markup HTML on
SQL> SHOW USER
spool index.html
SQL> SET PAGESIZE 100
select * from tab;
SQL> START myscrip.sql
spool off
set markup HTML off SQL commands
The spooled index.html will be an HTML file that can be opened in
any browser
SQL> SELECT * FROM user_tables;
PL/SQL blocks
BEGIN
dbms_output.put_line('Hello World!');
END;
/
SAL A bit of history: when SQL*Plus was still called UFI, this file
was called login.ufi (located in $ORACLE_HOME/demo).
----------
3000
How does one disable interactive prompting in SQL*Plus?
SQL> /
old 1: SELECT sal FROM emp WHERE ename LIKE '&&NAME'
new 1: SELECT sal FROM emp WHERE ename LIKE 'SCOTT' If you run a script that contains "&" symbols, SQL*Plus thinks
SAL that you want to prompt the user for a value. Some clients allow
---------- one to escape the ampersand character with a backslash, however,
3000 that doesn't work from SQL*Plus. Here is a couple of solutions:
The "&&" will actually define the variable similarly to what the SET ESCAPE ON
DEFINE command or OLD_VALUE/ NEW_VALUE clauses of a COLUMN SET ESCAPE ""
statement would have done. SELECT 'You & me' FROM DUAL;
SQL> define or
DEFINE NAME = "SCOTT" (CHAR) SET DEFINE ?
SELECT 'You & me' FROM DUAL;
What is the difference between ! and HOST? Atanas Kebedjiev provided this solution:
SELECT 'You '||Chr(38)||' Me' FROM DUAL;
Both "!" and "HOST" will execute operating system commands as
child processes of SQL*Plus. The difference is that "HOST" will Note: You can disable substitution variable prompting altogether
perform variable substitution (& and && symbols), whereas "!" by issuing the SET DEFINE OFF or SET SCAN OFF command.
will not. Examples:
SQL> ! whoami How does one trap errors in SQL*Plus?
oracle
SQL> DEFINE cmd="whoami" Use the "WHENEVER SQLERROR ..." command to trap SQL and PL/SQL
SQL> HOST &&cmd errors, and the "WHENEVER OSERROR ..." to trap operating system
oracle errors. Eg:
Note: use "$" under OS/390, VMS, and Windows environments, not SQL> WHENEVER OSERROR EXIT 9
"!". SQL> WHENEVER SQLERROR EXIT SQL.SQLCODE
Can one run commands when SQL*Plus starts up? How does one trace (and explain) SQL statements from SQL*Plus?
When SQL*Plus starts up, it looks for a global login script Method 1: Autotrace Facility
called glogin.sql in the $ORACLE_HOME/sqlplus/admin directory. If
found, this script will be executed. When the AUTOTRACE setting is enabled, SQL*Plus will print an
EXPLAIN PLAN and execution statistics after each SQL statement.
Thereafter, sqlplus will try to find a local login script called Look at this example:
login.sql in the directory where you start sqlplus from,
alternatively the directories listed in the SQLPATH environment SQL> set autotrace on
variable. When found, sqlplus will execute it. SQL> select * from dept where deptno = 40;
DEPTNO DNAME LOC