12.07.2015 Views

Oracle SQL Developer

Oracle SQL Developer

Oracle SQL Developer

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Using <strong>SQL</strong>*PlusA <strong>SQL</strong> script file is executed with a START or @ command. For example, on a Windowsenvironment you could execute a <strong>SQL</strong> script as follows:<strong>SQL</strong>> @c:\my_scripts\my_sql_script.sqlA <strong>SQL</strong> script file could be executed on a Linux environment as follows:<strong>SQL</strong>> START /home/cjones/my_scripts/my_sql_script.sqlYou can use SET ECHO ON to cause a script to echo each statement that is executed. Youcan use SET TERMOUT OFF to prevent the script output from displaying on the screen.When running a script, you should include the full path name unless the script islocated in the directory where <strong>SQL</strong>*Plus was launched.10.2.7 Spooling From <strong>SQL</strong>*PlusThe SPOOL command can be used to direct the output from <strong>SQL</strong>*Plus to a disk file,which enables you to save the output for future review.To start spooling the output to an operating system file, you can enter:<strong>SQL</strong>> SPOOL my_log_file.logIf you want to append the output to an existing file:<strong>SQL</strong>> SPOOL my_log_file.log APPENDTo stop spooling and close a file, enter the following:<strong>SQL</strong>> SPOOL OFF10.2.8 Using Variables With <strong>SQL</strong>*PlusYou can write queries that use variables to make your SELECT statements moreflexible. You can define the variable prior to running a <strong>SQL</strong> statement or you canprompt for a variable value at the time that the <strong>SQL</strong> statement is run.When using a variable in a <strong>SQL</strong> statement, the variable name must be begin with anampersand (&).This topic includes the following topics:■ Prompting for a Variable■ Defining a Variable Value for a QueryFor information on using bind variables in PL/<strong>SQL</strong> code, see Using Bind Variables.10.2.8.1 Prompting for a VariableIn Example 10–1, including the variable &emp_id causes the <strong>SQL</strong> statement to promptfor a value when the statement is executed. You can then enter the employee_id thatyou want to display, such as employee Id 125.Example 10–1 Defining a Variable-- prompt for employee_id in a query, you need to enter a valid Id such as 125SELECT employee_id, last_name, job_id FROM employees WHERE employee_id = &emp_id;When you run the previous SELECT statement, the output is similar to:Enter value for emp_id: 125...EMPLOYEE_ID LAST_NAME JOB_ID10-4 <strong>SQL</strong> <strong>Developer</strong> Online Help

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!