sql >> Database teknologi >  >> RDS >> Oracle

Udskrivning af en alfabetpyramide i PL/SQL

Denne virker:

DECLARE
    aLine VARCHAR2(100);
BEGIN
    FOR PyramidLevel IN 0..25 LOOP
        aLine := NULL;

        FOR i IN 0..PyramidLevel-1 LOOP
            aLine := aLine || CHR(i+65);
        END LOOP; 

        FOR i IN REVERSE 0..PyramidLevel LOOP
            aLine := aLine || CHR(i+65);
        END LOOP;
        aLine := LPAD(aLine, 26+PyramidLevel);       

       DBMS_OUTPUT.PUT_LINE('_'||aLine);
    END LOOP;
END;


_                         A
_                        ABA
_                       ABCBA
_                      ABCDCBA
_                     ABCDEDCBA
_                    ABCDEFEDCBA
_                   ABCDEFGFEDCBA
_                  ABCDEFGHGFEDCBA
_                 ABCDEFGHIHGFEDCBA
_                ABCDEFGHIJIHGFEDCBA
_               ABCDEFGHIJKJIHGFEDCBA
_              ABCDEFGHIJKLKJIHGFEDCBA
_             ABCDEFGHIJKLMLKJIHGFEDCBA
_            ABCDEFGHIJKLMNMLKJIHGFEDCBA
_           ABCDEFGHIJKLMNONMLKJIHGFEDCBA
_          ABCDEFGHIJKLMNOPONMLKJIHGFEDCBA
_         ABCDEFGHIJKLMNOPQPONMLKJIHGFEDCBA
_        ABCDEFGHIJKLMNOPQRQPONMLKJIHGFEDCBA
_       ABCDEFGHIJKLMNOPQRSRQPONMLKJIHGFEDCBA
_      ABCDEFGHIJKLMNOPQRSTSRQPONMLKJIHGFEDCBA
_     ABCDEFGHIJKLMNOPQRSTUTSRQPONMLKJIHGFEDCBA
_    ABCDEFGHIJKLMNOPQRSTUVUTSRQPONMLKJIHGFEDCBA
_   ABCDEFGHIJKLMNOPQRSTUVWVUTSRQPONMLKJIHGFEDCBA
_  ABCDEFGHIJKLMNOPQRSTUVWXWVUTSRQPONMLKJIHGFEDCBA
_ ABCDEFGHIJKLMNOPQRSTUVWXYXWVUTSRQPONMLKJIHGFEDCBA
_ABCDEFGHIJKLMNOPQRSTUVWXYZYXWVUTSRQPONMLKJIHGFEDCBA

Det ligner DBMS_OUTPUT.PUT_LINE() trimmer indledende mellemrumstegn (i hvert fald i min TOAD), så jeg sætter _ i begyndelsen.



  1. Oracle 2 bindestreger i talkolonnen?

  2. mysql konvertering fra UTC til IST

  3. Beregnet felt med værdi fra en anden tabel i Microsoft Access

  4. Beregn summen af ​​tidskolonnen i PostgreSql