lol
lol

Reputation: 3390

Script file with multiple commands

How can I run below script file in SQL*Plus.

Script file content:

variable a number; 

begin 
:a := 10; 
end; 

print a; 

How can I execute this in SQL*Plus?

EDIT

Script file name is: Question3.sql

I am getting following error:

enter image description here

Upvotes: 0

Views: 167

Answers (1)

Nick Krasnov
Nick Krasnov

Reputation: 27251

In order to execute a PL/SQL block in SQL*PLUS, you have to terminate it with the slash /. So, your file should look like this:

-- some_name.sql file
variable a number; 
begin 
  :a := 10; 
end; 
/
print a; 


SQL> @c:\some_name.sql

PL/SQL procedure successfully completed.


         A                                                                      
----------                                                                      
        10                                                                      

You could also use exec SQL*PLUS command to execute a single line command - assign a value to a bind variable in your case. exec command implicitly wraps a statement you are trying to execute in the begin end block:

-- some_name.sql file
variable a number; 
exec :a := 10; 
print a; 

SQL> @c:\some_name.sql

PL/SQL procedure successfully completed.


         A                                                                      
----------                                                                      
        10  

Upvotes: 4

Related Questions