Posts

Showing posts from March, 2014

SQL*Plus Tasks - SPOOL command

You want to save output from a SQL*Plus session to a file to get record of your actions, or because you are dynamically generating commands to execute later. This can be done in SQL*Plus with the help of SPOOL command: SQL> SPOOL report.txt SQL> @run_report.sql ...output scrolls past and gets written to the file report.txt... SQL> SPOOL OFF The first command, SPOOL report, tells SQL*Plus to save everything from that point forward into the file report.txt. The file extension of .lst is the default and can be overridden by supplying your own extension in the SPOOL command like specified above. SPOOL OFF tells SQL*Plus to stop saving the output and to close the file.

SQL*Plus Tasks - DEFINE Keyword

SQL*Plus can also create and manipulate its own in-memory variables, and it sets aside a few special variables that will affect its behavior. Actually, there are two separate types of variables in SQL*Plus: DEFINEs and bind variables. To assign a value to a DEFINE variable, you can use the DEFINE command: SQL> DEFINE X = "UMASARATH" To view the value of x, specify: SQL> DEFINE X DEFINE X               = "UMASARATH" (CHAR) SQL> You would refer to such a variable using an ampersand (&). SQL*Plus does a simple substitution before sending the statement to the Oracle database, so you will need single-quote marks around the variable when you want to use it as a literal string. SQL> select '&x' from dual; old   1: select '&x' from dual new   1: select 'UMASARATH' from dual 'UMASARAT --------- UMASARATH SQL>