Forum OpenACS Q&A: Difference between PL/SQL Procedure and PL/SQL Function

Difference between PL/SQL Procedure and PL/SQL Function
A PL/SQL function returns a value, a procedure does not. Oracle is picky about this. The following, for example, will cause an error:
SQL> create or replace function unity
return integer
as
begin
   return 1;
end;
/

begin
  unity();
end;
/
show errors

  2    3    4    5    6    7
Function created.

SQL> SQL>   2    3    4    unity();
  *
ERROR at line 2:
ORA-06550: line 2, column 3:
PLS-00221: 'UNITY' is not a procedure or is undefined
ORA-06550: line 2, column 3:
PL/SQL: Statement ignored
Because unity is a function, we must return its result into a variable...
SQL> declare
  v_result integer;
begin
  v_result := unity();
end;
/
show errors

  2    3    4    5    6
PL/SQL procedure successfully completed.
I think Postgres is not as picky.
Collapse
Posted by Don Baccus on
Postgres is just as picky, it just doesn't have procedures, only functions :)

That's because there's no procedureal language "mode" in Postgresql (when you say "declare" or "begin" in SQL*Plus it invokes the PL/SQL compiler, rather than the SQL processor).  In Postgres there's only the SQL processor, and the "hook" into programmatic languages is the functional call.

function should contain a return clause and it returns a value, where as procedure may return a value or it may not return a value