FireVortex
FireVortex

Reputation: 343

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

Upvotes: 8

Views: 12032

Answers (2)

Tony Andrews
Tony Andrews

Reputation: 132580

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.

Upvotes: 1

Vincent Malgrat
Vincent Malgrat

Reputation: 67722

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.

Upvotes: 13

Related Questions