How to display all tables on the left side in PL/SQL?
In PL/SQL, you can use the following methods to display all tables:
- Displaying messages in a database management system
- Print out
SET SERVEROUTPUT ON
DECLARE
table_name VARCHAR2(30);
BEGIN
FOR tables IN (SELECT table_name FROM all_tables) LOOP
table_name := tables.table_name;
DBMS_OUTPUT.PUT_LINE(table_name);
END LOOP;
END;
/
- The SYS.DBMS_SQL package
- An opened cursor
- Analyze or break down the information into smaller parts
- Carry out
DECLARE
cursor_id INTEGER;
table_name VARCHAR2(30);
BEGIN
cursor_id := DBMS_SQL.OPEN_CURSOR;
DBMS_SQL.PARSE(cursor_id, 'SELECT table_name FROM all_tables', DBMS_SQL.NATIVE);
DBMS_SQL.DEFINE_COLUMN(cursor_id, 1, table_name);
IF DBMS_SQL.EXECUTE(cursor_id) > 0 THEN
LOOP
IF DBMS_SQL.FETCH_ROWS(cursor_id) > 0 THEN
DBMS_SQL.COLUMN_VALUE(cursor_id, 1, table_name);
DBMS_OUTPUT.PUT_LINE(table_name);
ELSE
EXIT;
END IF;
END LOOP;
END IF;
DBMS_SQL.CLOSE_CURSOR(cursor_id);
END;
/
These methods will query the system view ALL_TABLES in a PL/SQL block and output the table names to the output window. Prior to utilizing these methods, make sure there is sufficient permissions to access the system views and packages.