0

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

1 Answer 1

4

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  
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.