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;
dplinnaneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

slightwv (䄆 Netminder) Commented:
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;
0
slightwv (䄆 Netminder) Commented:
I get it now........  sorry.

I haven't tested this but the idea should work (unless I'm still missing the point....which can easily happen):

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
dplinnaneAuthor Commented:
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;
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

slightwv (䄆 Netminder) Commented:
Better yet:

if str_switch = 'yes' then  
       dbms_output.put_line ('printed string ' || str_echo);
end if;
return null;
0
dplinnaneAuthor Commented:
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;
0
dplinnaneAuthor Commented:
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?
0
slightwv (䄆 Netminder) Commented:
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)
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.