Wednesday, March 26, 2014

dbms_output in SQL Developer.



In sqlplus , you can shorten some of the SET options and it works the same as if the full command is issued. 

For example , to print the output from dbms_output , you can either use SET SERVEROUT ON or SET SERVEROUTPUT ON. 

SQL> set serverout on
SQL> begin
  2     dbms_output.put_line ('hello Zahir');
  3  end;
  4  /
hello Zahir

PL/SQL procedure successfully completed.

SQL> set serveroutput on
SQL> begin
  2     dbms_output.put_line ('hello Zahir');
  3  end;
  4  /
hello Zahir

PL/SQL procedure successfully completed.



But in SQL developer it expects the full text of the command . If you the first set of commands ( aka SET SERVEROUT ON) , you would get a warning message .

line 1: SQLPLUS Command Skipped: set serverout on
anonymous block completed


If you issue the latter , it works fine.


3 comments:

  1. SET VERIFY OFF;
    SET SERVEROUPUT ON;

    DECLARE
    v_grade char(1):=UPPER('&grade');
    appraisal varchar(20);

    BEGIN
    appraisal:= CASE v_grade
    when 'A' then 'excellent'
    when 'B' then 'very good'
    when 'C' then 'good'
    else 'No such grade'
    END;
    dbms_output.put_line('Grade:'|| v_grade|| 'appraisal '||appraisal);
    END;

    ReplyDelete
    Replies
    1. Loose the semicolon in the SET commands.

      set verify off
      set serveroutput on
      DECLARE
      v_grade CHAR(1):=UPPER('&grade');
      appraisal VARCHAR(20);
      BEGIN
      dbms_output.put_line( 'v_grade '||v_grade);
      appraisal:=
      CASE v_grade
      WHEN 'A' THEN
      'excellent'
      WHEN 'B' THEN
      'very good'
      WHEN 'C' THEN
      'good'
      ELSE
      'No such grade'
      END;
      dbms_output.put_line('Grade:'|| v_grade|| 'appraisal '||appraisal);
      END;
      /

      Delete
  2. the above code is not displaying anything, plz provide the solution

    ReplyDelete