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:

  1. Displaying messages in a database management system
  2. 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;
/
  1. The SYS.DBMS_SQL package
  2. An opened cursor
  3. Analyze or break down the information into smaller parts
  4. 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.

Leave a Reply 0

Your email address will not be published. Required fields are marked *


广告
Closing in 10 seconds
bannerAds