SQL Tutorial
SQL Clauses / Operators
SQL-Injection
SQL Functions
SQL Queries
PL/SQL
MySQL
SQL Server
Misc
In PL/SQL, printing patterns using stars or any other characters is achieved through loops and conditional logic. Here are examples of some common star patterns using PL/SQL:
DECLARE n NUMBER := 5; BEGIN FOR i IN 1..n LOOP FOR j IN 1..i LOOP DBMS_OUTPUT.PUT('*'); END LOOP; DBMS_OUTPUT.PUT_LINE; END LOOP; END; /
DECLARE n NUMBER := 5; BEGIN FOR i IN REVERSE 1..n LOOP FOR j IN 1..i LOOP DBMS_OUTPUT.PUT('*'); END LOOP; DBMS_OUTPUT.PUT_LINE; END LOOP; END; /
DECLARE n NUMBER := 5; BEGIN FOR i IN 1..n LOOP FOR j IN 1..(n - i) LOOP DBMS_OUTPUT.PUT(' '); END LOOP; FOR k IN 1..(2 * i - 1) LOOP DBMS_OUTPUT.PUT('*'); END LOOP; DBMS_OUTPUT.PUT_LINE; END LOOP; END; /
DECLARE n NUMBER := 5; BEGIN -- Upper pyramid FOR i IN 1..n LOOP FOR j IN 1..(n - i) LOOP DBMS_OUTPUT.PUT(' '); END LOOP; FOR k IN 1..(2 * i - 1) LOOP DBMS_OUTPUT.PUT('*'); END LOOP; DBMS_OUTPUT.PUT_LINE; END LOOP; -- Lower pyramid (inverted) FOR i IN REVERSE 1..n-1 LOOP FOR j IN 1..(n - i) LOOP DBMS_OUTPUT.PUT(' '); END LOOP; FOR k IN 1..(2 * i - 1) LOOP DBMS_OUTPUT.PUT('*'); END LOOP; DBMS_OUTPUT.PUT_LINE; END LOOP; END; /
These patterns utilize nested loops. The outer loops are responsible for the number of rows, while the inner loops control the number of characters (stars or spaces) printed on each row.
To execute the above PL/SQL blocks, you'd typically use an environment like SQL*Plus or any other tool that supports Oracle databases and PL/SQL execution. The results would be printed on the console.
PL/SQL print star pattern example:
BEGIN DBMS_OUTPUT.PUT_LINE('*****'); END; /
How to create patterns in PL/SQL:
BEGIN -- Your pattern printing logic here... END; /
Printing numbers and shapes in PL/SQL:
BEGIN -- Your number and shape pattern printing logic here... END; /
Pattern printing using nested loops in PL/SQL:
BEGIN FOR i IN 1..5 LOOP FOR j IN 1..i LOOP DBMS_OUTPUT.PUT('*'); END LOOP; DBMS_OUTPUT.NEW_LINE; END LOOP; END; /
PL/SQL program to print pyramid pattern:
BEGIN FOR i IN 1..5 LOOP DBMS_OUTPUT.PUT_LINE(RPAD(' ', 5 - i, ' ') || RPAD('*', 2 * i - 1, '*')); END LOOP; END; /
Triangle pattern printing in PL/SQL:
BEGIN FOR i IN 1..5 LOOP DBMS_OUTPUT.PUT_LINE(RPAD('*', i, '*')); END LOOP; END; /
Square and rectangle patterns in PL/SQL:
BEGIN FOR i IN 1..5 LOOP DBMS_OUTPUT.PUT_LINE(RPAD('*', 5, '*')); END LOOP; END; /
Diamond pattern printing in PL/SQL:
BEGIN FOR i IN 1..5 LOOP DBMS_OUTPUT.PUT_LINE(RPAD(' ', 5 - i, ' ') || RPAD('*', 2 * i - 1, '*')); END LOOP; FOR i IN 4 DOWNTO 1 LOOP DBMS_OUTPUT.PUT_LINE(RPAD(' ', 5 - i, ' ') || RPAD('*', 2 * i - 1, '*')); END LOOP; END; /
Hollow pattern printing in PL/SQL:
BEGIN FOR i IN 1..5 LOOP IF i = 1 OR i = 5 THEN DBMS_OUTPUT.PUT_LINE(RPAD('*', 5, '*')); ELSE DBMS_OUTPUT.PUT_LINE('*' || RPAD(' ', 3, ' ') || '*'); END IF; END LOOP; END; /
Right-angled triangle pattern in PL/SQL:
BEGIN FOR i IN 1..5 LOOP DBMS_OUTPUT.PUT_LINE(RPAD('*', i, '*')); END LOOP; END; /
Pattern printing with characters in PL/SQL:
BEGIN FOR i IN 1..5 LOOP DBMS_OUTPUT.PUT_LINE(RPAD(CHR(64 + i), i, CHR(64 + i))); END LOOP; END; /
PL/SQL program to print alphabet patterns:
BEGIN FOR i IN 1..5 LOOP DBMS_OUTPUT.PUT_LINE(RPAD(CHR(64 + i), 5, CHR(64 + i))); END LOOP; END; /
Customizable pattern printing in PL/SQL:
DECLARE v_pattern_size NUMBER := 5; BEGIN FOR i IN 1..v_pattern_size LOOP DBMS_OUTPUT.PUT_LINE(RPAD('*', i, '*')); END LOOP; END; /
Star and number patterns in PL/SQL procedures:
CREATE OR REPLACE PROCEDURE print_star_pattern AS BEGIN DBMS_OUTPUT.PUT_LINE('*****'); END; / CREATE OR REPLACE PROCEDURE print_number_pattern AS BEGIN FOR i IN 1..5 LOOP DBMS_OUTPUT.PUT_LINE(i); END LOOP; END; /
Animation effects with pattern printing in PL/SQL:
DECLARE v_delay NUMBER := 1; BEGIN FOR i IN 1..5 LOOP DBMS_LOCK.sleep(v_delay); DBMS_OUTPUT.PUT_LINE(RPAD('*', i, '*')); END LOOP; END; /