Question

Asked on 2004-08-05 at 04:33:12ID: 25490653

Right aligning numbers in the output of an SQL Script

by: kunmun2350

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.

  1. sqlplus output value to be passed  to bash script …
    Can anyone advise-How can i retreive the output of following test sql file and used in bash script further. I am using following sqlplus line in bash script. i want the cnt value to be passed to bash script where cnt is a varable used in test.sql to store output. sqlplus xx/xx@DNYNTK01 @test.sql The test.sql file contains- set serveroutput o…
  2. query to Return the number of records and outpu…
    What I am looking to do is do a select count(*) on every column in a table where it is not null and then output it to a text file. Can someone give me an example of this and send it over. Below is what I am looking to do. BEGIN   //Perform a Query  for multiple fields:  Select count(*) from CC_TABLENAME where CC_TABLENA…
  3. ORACLE -- SQL -- Inner/Left/Right Joins
    --#1 = below gets 12 rows (SELECT fmrc.fmrescomponentid, fmr.fmcode, fmrc.fmpercentage, fmr.fmentityobjectid FROM fmresourcecmp fmrc INNER JOIN fmresource fmr ON fmrc.fmresourceid = fmr.fmentityobjectid WHERE fmr.fmcode LIKE UPPER('A1454')) --#2 = below gets additional columns, still …
  4. sql script
    Hi I have a script and I am not sure what its doing .Can someone please explain the script to me . Would appreciate it , thanks.
  5. commit statement in sql script
    Guys I have an sql script that I autogenerates an output. I would like to also have it add a commit to either every line or in blocks of say 100 can this be done without me adding in manually commit every so often I have attempted to do this but sqlplus doesnt recognise this so it fails. Any Ideas

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

Posted on 2004-08-05 at 04:35:05ID: 28411785

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

Posted on 2004-08-05 at 05:01:32ID: 28411786

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

Posted on 2004-08-05 at 05:12:04ID: 28411787

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

Posted on 2004-08-05 at 06:42:28ID: 28411788

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:

Posted on 2004-08-05 at 21:59:09ID: 28411789

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

Posted on 2004-08-05 at 22:26:15ID: 28411790

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. slightwv

    2,000

    0 points yesterday

    Profile

BrowseBecome an Expert