Link to home
Start Free TrialLog in
Avatar of dplinnane
dplinnaneFlag for United States of America

asked on

return dbms_output.put_line ('etc'); from function fails error = PLS-00222: no function with name 'PUT_LINE' exists in this scope

When I compile in Toad it fails I get the same error if I pass value to str_value but no errors if I use something like retur upper('str_echo').
I basically want to have a print statement through out my code that I can switch on and off for debugging. Any suggestions? Thanks Patrick.

CREATE OR REPLACE package body dr_lib_package
as
   function fx_echo (str_switch in varchar2, str_echo in varchar2)
      return varchar2
   is
      str_value   varchar2 (2000) := null;

   begin
   
   if str_switch = 'yes' then  
       return  dbms_output.put_line ('printed string ' || str_echo);
      --str_value := dbms_output.put_line ('printed string ' || str_echo);
      --return str_value;
   else
      return null;
   end if;
   
   end fx_echo;
end dr_lib_package;
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

dbms_output.put_line is only used to dump output to the screen (console).

change:
 return  dbms_output.put_line ('printed string ' || str_echo);

to

 return  'printed string ' || str_echo;
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dplinnane

ASKER

You just have to make the function is returing something, so return null works no need to use return  'printed string ' || str_echo;
Thanks this will do.

if str_switch = 'yes' then  
       dbms_output.put_line ('printed string ' || str_echo);
       return null;
   else
      return null;
   end if;
Better yet:

if str_switch = 'yes' then  
       dbms_output.put_line ('printed string ' || str_echo);
end if;
return null;
Better agin maybe using a procedure because I do not need value passed to a variable, I posted another quest just a few mins ago about adding a line number to print statement so I know which print statement is being printed to screen, if you have any suggestions check it out. Q  = is there a LINE variable in Oracle, need...

procedure pr_echo (str_switch in varchar2, str_echo in varchar2)

   is

   begin
   
         if str_switch = 'yes' then  
        
         dbms_output.put_line ('printed string ' || str_echo);
        
         end if;
   
   end pr_echo;
Problem when I run dr_lib_package.pr_echo ('on', v_test||'procedure name =   '||v_procedure_nm); in another package I get nothing returned to the screen. Not sure why oracle doen't have a simple echo or print variable? Any ideas why nothing is printed out?
I've never attempted what you are attempting so I have no specific asnwer.

That said, make sure serveroutput is on and has an adequate size (This gets turned off by default)