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.

  1. 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 g…
  2. output format
    Hi we have following php script that pulls the information from mysql and gives output. Right now it is fetching only one record based on the where condition. I need help to modify the script to display all records from the table. and the output in delimiter format for example col1;col2;col3 col1;col2;col3 like such. Thanks
  3. PL/SQL code - DBMS_OUTPUT.PUT_LINE
    I'm trying to see the result from a spool file but I only got "PL/SQL procedure successfully completed." How do I get to see the resutl from a spool file? set serveroutput on spool c:\test.log DECLARE v_rec_text VARCHAR2(500); v_fallback_plan VARCHAR2(10); v_fallback_plan_rate number…
  4. 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_TABLENAM…
  5. 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 on…

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

    2,000

    0 points yesterday

    Profile

BrowseBecome an Expert