Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between BEGIN/END and EXEC

what is the difference between

Begin
 bc_any_package_pkg.anyProcedure;
End;
/

and

EXEC bc_any_package_pkg.anyProcedure;
/

I can't find if there is any difference...

Thanks

like image 434
FireVortex Avatar asked Sep 03 '13 08:09

FireVortex


2 Answers

EXECUTE (short EXEC) is a SQL*Plus command that basically wraps a BEGIN END block around your one-liner:

Executes a single PL/SQL statement. The EXECUTE command is often useful when you want to execute a PL/SQL statement that references a stored procedure.

They really are the same when using SQL*Plus, although exec is faster to type.

This is not standard PL/SQL, which means that if you use any other tool than SQL*Plus, there is a chance that exec will not be recognized. It also only works with single lines.

Whereas BEGIN END is standard and will work with any tool that interfaces with PL/SQL. Such blocks can also span more than one line.

like image 73
Vincent Malgrat Avatar answered Sep 30 '22 17:09

Vincent Malgrat


EXEC (or EXECUTE in its full form) is a SQL Plus command that executes a single PL/SQL statement. So it achieves exactly the same effect as writing an anononymus block of PL/SQL.

like image 38
Tony Andrews Avatar answered Sep 30 '22 16:09

Tony Andrews