sqlplus script end of file [message #625590] |
Fri, 10 October 2014 13:26 |
|
anncao
Messages: 87 Registered: August 2013
|
Member |
|
|
We have a lot of sqlplus scripts that spool data to text file.
I have a question about the last few lines that exit the script.
Here is an simplized example of our script:
set heading off
set feedback off
set newpage none
set echo off
set termout off
set verify off
set trimspool on
spool &&1.
Select s.student_number , s.middle_name , s.last_name,s.school_number
from students s;
spool off
/
exit
/
My question is for the last 5 lines, is it a good practice or right way of doing so? I know semicolon means to run that sql statement, what does the first / mean here? and second / mean?
The reason I asked this is because recently we found out one of scripts ends with
something like below:
spool &&1.
Select s.student_number , s.middle_name , s.last_name,s.school_number
from students s;
/
exit
/
It caused the script to run twice, I found out is because the use of ; and / together made it run twice.
Also some script use a ; after exit, then /, is it necessary to use the ;
Thanks
|
|
|
|
|
|
Re: sqlplus script end of file [message #625594 is a reply to message #625593] |
Fri, 10 October 2014 14:53 |
|
anncao
Messages: 87 Registered: August 2013
|
Member |
|
|
My own test shows the output has the same number of records in the select statement if I use
below:
Select s.student_number , s.middle_name , s.last_name,s.school_number
from students s;
spool off
/
exit
/
So that means only ran one time. If I put / right after; it will run twice.
But now I just want to know what in above statement the first and second / mean here?
Thanks
[Updated on: Fri, 10 October 2014 14:54] Report message to a moderator
|
|
|
|
|
|
|
|
|
|
|
|
Re: sqlplus script end of file [message #625606 is a reply to message #625605] |
Fri, 10 October 2014 17:17 |
|
anncao
Messages: 87 Registered: August 2013
|
Member |
|
|
Also searched on the web, thought this is helpful too.
From my understanding, all the SQL statement don't need forward slash as they will run automatically at the end of semicolons, including DDL, DML, DCL and TCL statements. For other PL/SQL blocks, including Procedures, Functions, Packages and Triggers, because they are multiple line programs, Oracle need a way to know when to run the block, so we have to write a forward slash at the end of each block to let Oracle run it.
|
|
|
|