Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Oracle SQL Stored Procedures Call vs. Execute

Tags:

Problem

I'm trying to understand the difference between Oracle SQL commands CALL and EXECUTE.

I've been using CALL to kick off stored procedures but in talking with another developer I found that he almost exclusively uses EXECUTE. I did some research online to see if I was doing something incorrectly but I'm not seeing the clear distinction between the two commands and people seem to use them interchangeably.

Based on the documentation, they seem remarkably similar (at least in terms of interacting with stored procedures).

  • http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_4008.htm
  • http://docs.oracle.com/cd/B19306_01/server.102/b14357/ch12022.htm
  • http://docs.oracle.com/cd/B28359_01/olap.111/b28126/dml_app_dbms_aw026.htm

It does look like CALL is a universal SQL command while EXECUTE seems to be proprietary so I would be inclined to use CALL over EXECUTE but then again I don't know what that means in regards to performance.

Questions

  • Is one preferable over the other in terms of kicking off a stored procedure? Does it matter?
  • If it does matter, what is a situation where either is appropriate?
  • Are there any performance differences between the two? What's best practice?
like image 909
DanK Avatar asked Dec 13 '13 16:12

DanK


People also ask

What is call in stored procedure?

Using get to call a stored procedure You can use the get keyword with a dynamic array to call only stored procedures that return exactly one result set. To call a stored procedure that does not return a result set or that returns more than one result set, use execute.

What is call procedure in SQL?

The CALL (PROCEDURE) statement is used to call procedures. A call to a procedure does not return any value. When a procedure with definer's rights is called, the current default schema is set to the eponymously named schema of the definer.

Can we call procedure within procedure?

A function cannot call the procedure inside the program's body.


1 Answers

Both EXEC[ute] SP() and CALL SP() could be used in SQL*Plus to execute an SP. BTW, you can also use BEGIN SP(); END;

But there are some differences.

  1. CALL is Oracle SQL and should work everywhere. Other DB clients that can talk to Oracle may or may not support SQL*Plus EXEC. Many do (for example, Oracle SQL Developer, SQLWorkbench/J), but some don't (Liquibase).

  2. The data types of the parameters passed by the CALL statement must be SQL data types. They cannot be PL/SQL-only data types such as BOOLEAN.

  3. EXEC could be used to execute not only an SP, but an arbitrary statement.

  4. If an SP does not have parameters, you can use EXEC SP; syntax, but CALL requires empty parentheses: CALL SP();

like image 110
Dmitriy Korobskiy Avatar answered Nov 07 '22 03:11

Dmitriy Korobskiy