开发者

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.P开发者_开发问答UT_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;
/
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜