Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to execute a dynamic sql statement in sql*plus

I would like to modify a value by using a dynamic sql statement. The example is choosen to be reproductible. I know that I don’t need a dynamic sql statement for that.

variable a number =1;
print a 

1

exec execute immediate 'select 2 into :a from dual'

PL/SQL procedure successfully completed.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

 print a

1

1 is returned instead of 2. It means that my statement wasn’t executed.
What should I do?

>Solution :

INTO should be out of execute immediate:

SQL> var a number = 1;
SQL> print a

         A
----------
         1

SQL> exec execute immediate 'select 2 from dual' into :a;

PL/SQL procedure successfully completed.

SQL> print a

         A
----------
         2

SQL>
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading