Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

output is not in proper way while using if condition?

Rajesh123Jun 8 2015 — edited Jun 9 2015

Hi all,

CREATE TABLE TEST_CASE

AS

  select *

  from (

  select 0.1 amount from dual

  union all

  select 0 from dual

  union all

  select 0 from dual

  union all

  select -1.22 from dual

  union all

  select -7.12 from dual

      );

DECLARE

   CURSOR c1

   IS

      SELECT * FROM TEST_CASE;

   v_acc_1   VARCHAR2 (1000);

   v_acc_2   VARCHAR2 (1000);

BEGIN

   DBMS_OUTPUT.put_line ('    Account   1  ' || '  , ' || '     Account   2  ');

   FOR c_rec IN c1

   LOOP

      v_acc_1 := NULL;

      v_acc_2 := NULL;

      IF c_rec.amount < 0

      THEN

         v_acc_1 := v_acc_1 || LPAD (NVL (TO_CHAR (c_rec.amount), ' '), 17);

      ELSE

         v_acc_2 := v_acc_2 || LPAD (NVL (TO_CHAR (c_rec.amount), ' '), 12);

      END IF;

      DBMS_OUTPUT.put_line (v_acc_1 || '   ,  ' || v_acc_2);

   END LOOP;

END;

Account_1   ,     Account_2

,            .1

,             0

,             0

-1.22   ,

-7.12   ,

PL/SQL procedure successfully completed.

If remove the If condition then it will be fine

Thanks

Message was edited by: Rajesh123 corrected table_name

This post has been answered by TPD-Opitz on Jun 8 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 7 2015
Added on Jun 8 2015
44 comments
588 views