Oracle - Function/Procedure call with output to console

February 15, 2013

Take the following Oracle function as example:

sql>create or replace
function “func_get_project_id” (p_project_code varchar2) return varchar2 is
  param_value varchar2(255);
  begin
    select project.id into param_value from project, costelement where project.costelementid = costelement.id and code = p_project_code;
    return param_value;
  exception
    when others then                                     
      return sqlerrm;
end func_get_project_id;

1- The first option is to call the function using a select:

sql>select func_get_project_id(‘e/0900-04’) from dual;

2- The second option is to set the activate the server output:

sql>set serveroutput on
sql>exec dbms_output.put_line( func_get_project_id(‘e/0900-04’));

3- The third and last option is to set the activate the server output via PL/SQL:

sql>(…)
  param_value varchar2(255);
  begin
    dbms_output.enable (1000000);
    select project.id into param_value from project, costelement where project.costelementid = costelement.id and code = p_project_code;
(…)

sql>exec dbms_output.put_line( func_get_project_id(‘e/0900-04’));