简体   繁体   中英

Generating a report in Oracle?

I am trying to generate a report using Oracle but am having some alignment problems. Is there a way to print values in particular columns? I am trying to achieve the following:

---------------------------------------------------------
ColA        ColB        ColC
-----     ---------   ---------
1            2           1
2            4           2
3            3           1

Currently, I am having some difficulty. I am writing the following PL/SQL command:

DECLARE

BEGIN
    DBMS_OUTPUT.PUT_LINE('-');
    DBMS_OUTPUT.PUT_LINE('----------------------------------------------------------------------------------------------------------------');
    DBMS_OUTPUT.PUT_LINE('ColA        ColB        ColC');
    DBMS_OUTPUT.PUT_LINE('-----------        ------------        -------');
    FOR record IN (SELECT * FROM TABLEA) LOOP
        DBMS_OUTPUT.PUT_LINE(record.ID || '        ' || record.TAG || '        ' || record.TIP);
    END LOOP;
END;
/

I am manually putting in eight spaces so my output is being messed up completely. Is there a better way to format the output?

Never mind.. I figured it tout... Just in case anyone else is looking for an answer, using RPAD gives me what I want. For instance, I can format it nicely using the following:

DECLARE

BEGIN
    DBMS_OUTPUT.PUT_LINE('-');
    DBMS_OUTPUT.PUT_LINE(RPAD('-', 50, '-');
    DBMS_OUTPUT.PUT_LINE(RPAD('ColA', 20) || RPAD('ColB', 20) || RPAD('ColC', 20));
    DBMS_OUTPUT.PUT_LINE('-----------        ------------        -------');
    FOR record IN (SELECT * FROM TABLEA) LOOP
        DBMS_OUTPUT.PUT_LINE(RPAD(record.ID, 20) || RPAD(record.TAG, 20) || RPAD(record.TIP, 20));
    END LOOP;
END;
/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM