Home » SQL & PL/SQL » SQL & PL/SQL » function is not giving correct output
function is not giving correct output [message #651766] Tue, 24 May 2016 21:19 Go to next message
AmarendraSahoo2016
Messages: 1
Registered: May 2016
Location: India
Junior Member

create or replace
FUNCTION GRADECOM (  GRADE IN VARCHAR2  ) 
RETURN VARCHAR2 IS 
COMMENTS VARCHAR2(30); 
BEGIN 
    CASE GRADE
          when 'A' then dbms_output.put_line('Excellent');
          when 'B' then dbms_output.put_line('Very good');
          when 'C' then dbms_output.put_line('Well done');
          when 'D' then dbms_output.put_line('You passed');
          when 'F' then dbms_output.put_line('Better try again');
          else dbms_output.put_line('No such grade');
       END CASE;
      RETURN NULL;
END GRADECOM;


select gradecom('A') from dual;

Output:
null


Expected: it should give excellent.

Where it is going wrong? Please help.
Re: function is not giving correct output [message #651772 is a reply to message #651766] Tue, 24 May 2016 22:24 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Welcome to this forum.

Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.

SET SERVEROUTPUT ON
Re: function is not giving correct output [message #651779 is a reply to message #651766] Wed, 25 May 2016 00:10 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Quote:
Output:
null


This is expected, your function returns only one value: NULL.

Replace all dbms_output call by a RETURN statement.

Re: function is not giving correct output [message #651789 is a reply to message #651766] Wed, 25 May 2016 02:50 Go to previous messageGo to next message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
It looks like there have been plenty of responses on the OTN forum:

https://community.oracle.com/thread/3933524
Re: function is not giving correct output [message #651790 is a reply to message #651789] Wed, 25 May 2016 02:54 Go to previous message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
And it looks like the OP is not willing to provide feedback.

Previous Topic: Need to populate two more columns
Next Topic: join table for top 5 and bottom 5
Goto Forum:
  


Current Time: Wed Apr 24 10:43:36 CDT 2024