SQL Editor
Executing Statements
Press F9
OR
Click the Execute Statement button on the toolbar.
If you only want to process a portion of the edit text
Highlight that portion AND :
Press F9
OR
Click the Execute Statement button.
To execute a single statement among many statements (separated by at least one blank line)
Click or place the caret/cursor within the statement you want to execute AND:
Press <SHIFT> F9 OR <CTRL><ENTER>
OR
Click the Run Current Statement button on the toolbar.
Toad supports query statements, DDL statements, blocks of procedure SQL, etc.
Toad recognizes substitution variables in quotes as follows:
If & is escaped, Toad will not prompt for a value.
If & is the last character in a string, it is not considered a substitution variable.
65
Toad for Oracle
Bind Variables
You can execute SQL statements in the SQL Editor using bind variables, where a colon leads the bind variable name, e.g.,
Select * from employee where last_name = :NAME and Toad will present the Variables popup window for you to input the value for the NAME bind variable. The values you enter are stored and retrieved for subsequent queries in the PARAMS.TXT file in the Toad\User Files folder.
Substitution Variables
You can also execute SQL statements with substitution variables where the ampersand leads the substitution variable name, e.g.,
SELECT * FROM &schema.EMPLOYEE
and Toad will present the same Variables popup window for you to enter the value for &schema. If you want to query DEMO.EMPLOYEE, enter DEMO. If you wanted to query SCOTT.EMPLOYEE, enter SCOTT.
66
SQL Editor
Execute SQL Scripts
The SQL Edit window can process SQL scripts that contain DDL statements,
Insert statements, and more. Some SQL*Plus commands are ignored as Toad processes a SQL script. For scripts that contain other SQL*Plus commands, you can still execute your script using the SQL Editor | Execute SQL Window via
SQL*Plus menu item.
A script that is opened in the SQL Editor, edited, and then executed via
SQL*Plus is AUTOMATICALLY SAVED TO DISK before Toad passes it to
SQL*Plus for execution.
SQL*Plus Script Execution statements that are supported include:
@
@@
&
&&
ACCEPT
BREAK/BRE
BTITLE/BTI
CLEAR (CLEAR SCREEN, SQL, BUFFER not supported)
COLUMN/COL
COMPUTE/COMP (SUM, MIN, and MAX supported at one level of detail)
CONNECT/CON and DISCONNECT/DISC
DEFINE/DEF and UNDEFINE/UNDEF (CONNECT IDENTIFIER, SQLPLUS,
RELEASE, EDITOR not supported)
EXEC/EXECUTE
EXIT/QUIT
PAUSE/PAU
PASSWORD
67
Toad for Oracle
PROMPT/PRO
PRINT
REM/REMARK
REPFOOTER
REPHEADER
SET APPINFO
SET AUTOTRACE/AUTOT (default OFF)
SET DEFINE/DEF (default ON)
SET ECHO (default ON)
SET ESCAPE/ESC
SET FEEDBACK/FEED
SET HEADING/HEA (default ON)
SET LINESIZE/LINES (default 80, maximum 2000)
SET SCAN (default ON)
SET SERVEROUTPUT/SERVEROUT (default OFF) - (ON and OFF supported, SIZE supported)
SET SHOW
SET TERMOUT/TERM (default ON)
SET TIMING
SET VERIFY
SET WRAP
SHOW
SPOOL Filename and SPOOL OFF (also SPO) - (In Toad, non-pathed files are created in the Toad directory. In Quest ScriptRunner, non-pathed files are created in the same directory as Quest ScriptRunner. It supports relative spool paths. It passes the SPOOL file to sub-scripts.)
68
SQL Editor
/ Slash (Required as a separator between certain commands (anonymous blocks, PL/SQL, and Create Type statements). This does not run the contents of the buffer, because Toad does not store a command buffer the same way
SQL*Plus does.)
START
STORE SET
TTITLE
VARIABLE
WHENEVER OSERROR
WHENEVER SQLERROR
SET ARRAYSIZE
SET AUTOCOMMIT
SET AUTOPRINT
SET AUTORECOVERY
SET BLOCKTERMINATOR
SET CMDSEP
SET COLSEP
SET COMPATIBILITY
SET CONCAT
SET COPYCOMMIT
SET COPYTYPECHECK
SET DESCRIBE
SET EDITFILE
69
Toad for Oracle
SET EMBEDDED
SET FLAGGER
SET FLUSH
SET HEADSEP
SET INSTANCE
SET LOBOFFSET
SET LOGSOURCE
SET LONG
SET LONGCHUNKSIZE
SET MARKUP
SET NEWPAGE
SET NULL
SET NUMFORMAT
SET NUMWIDTH
SET PAGESIZE
SET PAUSE
SET RECSEP
SET RECSEPCHAR
SET SHIFTINOUT
SET SQLBLANKLINES
SET SQLCASE
SET SQLCONTINUE
SET SQLNUMBER
SET SQLPREFIX
70
SET SQLPROMPT
SET SQLTERMINATOR
SET SUFFIX
SET TAB
SET TIME
SET TRIMOUT
SET TRIMSPOOL
SET UNDERLINE
DEL
EDIT
GET
HELP
HOST
INPUT
APPEND
ARCHIVE LOG
ATTRIBUTE
CHANGE
CLEAR SCREEN
CLEAR SQL
CLEAR BUFFER
COPY
SQL Editor
71
Toad for Oracle
LIST
RECOVER
RUN
SAVE
SHUTDOWN
STARTUP
72
SQL Editor
Table/View Aliases
Setting up table or view aliases permits a shortcut for entering columns of a query.
The ALIASES.TXT file is in the Toad\User Files directory. It should look like this: table_name=alias such as:
AAX_ACCESSGROUP_APPLICATION=aax
ACA_ACTIVITY_ACTION=aca
ACC_ACTIVITY_CATEGORY=acc
ACD_ACTION_DESCRIPTION=acd
ACP_ACTIVITY_CONTACT_PARTIC=acp
ACT_ANALYSIS_CATEGORY_TYPE=act
ADD_ADDENDUM=add
ADT_ADDRESS_TYPE=adt
AFP_ACTIVITY_FIRM_PARTIC=afp
AGX_APPLICATION_GROUP_ITEM=agx
DEPARTMENT=dept
To use, simply type something like: select dept.
and a column list will popup for the DEPARTMENT Oracle table.
If you set up these table aliases in ALIASES.TXT, they will be presented on the
SQL Modeler dialog when you select that table to build your query.
73
Toad for Oracle
To complete the SELECT SQL statement above, use Auto Replace Substitutions named similarly to the table aliases. These are accessible through the Edit|
Editor Options| Auto Replace tab. However, it would take you a long time to add a reasonably sized schema, so it is recommended that you edit \User
Files\PLSQLSUB.TXT. It should look like this: aax_ = AAX_ACCESSGROUP_APPLICATION aax aca_ = ACA_ACTIVITY_ACTION aca acc_ = ACC_ACTIVITY_CATEGORY acc acd_ = ACD_ACTION_DESCRIPTION acd acp_ = ACP_ACTIVITY_CONTACT_PARTIC acp act_ = ACT_ANALYSIS_CATEGORY_TYPE act add_ = ADD_ADDENDUM add adt_ = ADT_ADDRESS_TYPE adt afp_ = AFP_ACTIVITY_FIRM_PARTIC afp agx_ = AGX_APPLICATION_GROUP_ITEM agx dep_ = DEPARTMENT dept i.e., string = string to replace it with
You might want to use the underline _ because it is not as likely that a command will end with the underline _ symbol. Having the alias at the end keeps things tidy. If you type: select dept.
the popup should appear. Select your column name, then continue.
select dept.NAME
from dep_
Press the spacebar and it autocompletes...
select dept.NAME
from DEPARTMENT dept
If you edit ALIASES.TXT or PLSQLSUB.TXT, be sure to close and reopen Toad to re-read the list.
74