Question

Right aligning numbers in the output of an SQL Script

Rating7.4Very Good

SET ECHO OFF;
SET SERVEROUTPUT ON;

COLUMN v1 FORMAT A25;
COLUMN v2 FORMAT 999;

Declare CURSOR MYCUR IS
SELECT tname,cname
FROM col
WHERE cname LIKE '%DM_NAME%';
TABLELIST MYCUR%ROWTYPE;
TB constant varchar2(2):=CHR(9) || CHR (9); -- equal to TAB
v1 char(25);
v2 number;
sql_stmt varchar2(250);
--sql_del_stmt varchar2(250);
BEGIN
DBMS_OUTPUT.ENABLE(10000);
DBMS_OUTPUT.PUT_LINE('TABLE NAME' || TB || TB || 'RECORD COUNT');
DBMS_OUTPUT.PUT_LINE('----------' || TB || TB || '------------');

OPEN MYCUR;
  LOOP
     FETCH MYCUR INTO TABLELIST;
     EXIT WHEN MYCUR%NOTFOUND;
       --sql_del_stmt:='DELETE FROM ' || TABLELIST.tname || ' WHERE ' || TABLELIST.cname || ' LIKE ''%HUB_Inventory%'' ' ;      
      sql_stmt:='SELECT ''' || TABLELIST.tname || ''' Table_Name, COUNT(*) Record_Count FROM ' || TABLELIST.tname || ' WHERE ' || TABLELIST.cname || ' LIKE ''%HUB_Inventory%'' ' ;
      Begin
            EXECUTE IMMEDIATE sql_stmt into v1,v2;
            
            --DBMS_OUTPUT.PUT_LINE(sql_stmt);
            --DBMS_OUTPUT.PUT_LINE(sql_del_stmt);                        
       DBMS_OUTPUT.PUT_LINE(v1 || TB || v2);
      end;
  END LOOP;
CLOSE MYCUR;
END;
/
This scripts gives an output like:

^----------------
Statement Ignored
^----------------
Statement Ignored

TABLE NAME                    RECORD COUNT
----------                          ------------
REVIEW_PUBLISH_MAPPING               0
ROLE_TGVIEW_INFO                     12
TG_VIEW_INFO                         3
USER_PROBLEM_SUMMARY                 0
PL/SQL procedure successfully completed

I would like to see the numbers right aligned. Any suggestions ? Tried LPAD function and some other things too..so far no success. Please help.

See More

Solution

Sign up now to view this solution! It's quick, easy, and secure to subscribe. We will return you to this solution, unlocked, when you’re done.

About this Solution
View This Solution - Start Your 30 Day Free Trial
Zone
General
Tags
Participating Experts
1
Solution Grade
A

Replies

 
by: kunmun23

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 
by: kunmun23

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 
by: Henka

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 
by: kunmun23

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 
by:

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

 
by: kunmun23

All comments and solutions are available to Premium Service Members only. Sign up to view the solution to this question. Already a member? Log in to view this solution.

Stay Connected

Oracle Around the Web

The latest Oracle news, tips, and tricks

Oracle Unveils Netra SPARC T3 Servers

New Carrier-Grade Blade and Rackmount Servers Deliver Better Performance, Density and Power Efficiency for the Communications Industry ...

read more

Oracle fixes 21 flaws in Java SE, Java for Business

Oracle is fixing 21 flaws in its Java SE and Java for Business products in its February critical patch update issued this week ...

read more

Obama’s Silicon Valley “Tech Supper”

Why was he there? Who wasn’t invited and why? What did they talk about? Why was he really there? These are the questions being debated ...

read more

Featured Oracle Experts

slightwv

slightwv has answered more than 2,000 Oracle questions and oversees database management within the U.S. Government. Slightwv

sdstuber

A regular presenter at the Collaborate conference, Oracle developer sdstuber is a top expert in PL/SQL and Oracle 9, 10 and 11. sdstuber

Testimonials

What users are saying about our experts

"The Oracle gurus provide answers, solutions and valuable workarounds"

User: schwertner

"Wow! Excellent, valuable explanation. Hats off to you"

User: aseshu70

"Solution worked fantastic and performs excellent! Thanks heaps"

User: klausbrandlhuber

Top Experts

  1. johnsone

    2,000

    0 points yesterday

    Profile
  2. slightwv

    2,000

    0 points yesterday

    Profile

BrowseBecome an Expert