Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Databases
  • SQL
  • MySQL
  • PostgreSQL
  • PL/SQL
  • MongoDB
  • SQL Cheat Sheet
  • SQL Interview Questions
  • MySQL Interview Questions
  • PL/SQL Interview Questions
  • Learn SQL and Database
Open In App
Next Article:
How to Show a List of Databases in PL/SQL?
Next article icon

How to Show Database in PL/SQL

Last Updated : 24 Apr, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

PL/SQL is the Procedural Language/Structured Query Language and serves as a procedural language built-in extension to SQL language, which allows seamless integration of procedural constructs with SQL. One of the most common functions of a DBMS is the retrieval of information about databases which is fundamental for administrators and programmers alike.

In this manual, we will explain how to perform database display via PL/SQL, including methods for retrieving information on PDBs, users, and objects.

Showing Databases

We are going to understand databases in PL/SQL using processing the next methods - querying data dictionary views, dynamic SQL implementation, and others. The abovementioned, we will cover the methods particular to the PDBs retrieval data, users, and even objects.

Using Data Dictionary Views

Oracle provides a rich set of data dictionary views containing metadata about database objects. These views are invaluable for retrieving information about databases, tablespaces, users, and objects. Here are some commonly used views:

  • DBA_DATA_FILES: It Gives information about data files, such as tablespace, file name, and size.
  • DBA_TABLESPACES: It Contains information about tablespaces, like their name, size, and the way of extent management.
  • DBA_USERS / ALL_USERS: It Provides information about database users, such as their usernames, roles, and default tablespaces.
  • ALL_OBJECTS: It Contains details of database objects accessible to the current user, which include their names, types, and owners.

Examples of How to Show a Database in PL/SQL

Let us say that we have an Oracle database with various numbers of Pluggable Databases (PDBs), users, and database objects. We'll do the examples using sample queries to fetch information about those databases, users, and objects.

1. Retrieving information about Pluggable Databases (PDBs)

-- Example: Retrieving information about Pluggable Databases (PDBs)
SELECT name, open_mode FROM v$pdbs;

Output:

NAME

OPEN_MODE

PDB1

READ WRITE

PDB2

READ ONLY

PDB3

READ WRITE

Explanation: The output displays the names and open modes of the Pluggable Databases (PDBs) in the Oracle database. For each PDB, the name of the PDB is listed along with its open mode, indicating whether it is in read-write or read-only mode.

2. Retrieving Information About Database Users

-- Example: Retrieving information about database users
SELECT username, account_status FROM dba_users;

Output:

USERNAME

ACCOUNT_STATUS

SYS

OPEN

SYSTEM

OPEN

HR

OPEN

SCOTT

OPEN

Explanation: The output lists the usernames and account statuses of the database users. Each row represents a user, with the username displayed in the first column and the account status (such as "OPEN") displayed in the second column.

3. Retrieving Information About all objects in the Database

-- Example: Retrieving information about all objects in the database
SELECT object_name, object_type FROM all_objects;

Output:

OBJECT_NAME

OBJECT_TYPE

EMPLOYEES

TABLE

DEPARTMENTS

TABLE

JOBS

TABLE

Explanation: The output provides details about database objects accessible to the current user. Each row represents an object, with the object name displayed in the first column and the object type (e.g., "TABLE") displayed in the second column. This information helps users understand the types of objects present in the database

Best Practices

When showing databases in PL/SQL, adhere to best practices to ensure efficiency, security, and maintainability:

  • Privilege management: Make certain that the executing user has required privileges for he/she will have access to required database objects.
  • Parameterized queries: Parameterization of queries will help in evading vulnerabilities such as SQL injection attacks and also help in code reusability.
  • Exception handling: Institute an error handling design to smoothly contain and deal with errors.
  • Performance optimization: Frequently index frequently queried columns and SQL queries are ed by optimization to enhance performance

Conclusion

Overall using PL/SQL the database which will provide information on database structure, usage, and performance is essential. Using data dictionary views, system tables, and dynamic SQL queries, users can have access to information about databases, PDBs, users, and objects relevant to their needs. Observing procedures for good habits guarantees effective and safe database maintenance in the PL/SQL environment. Having a well-grasped understanding of these approaches, the users can get around and handle Oracle databases efficiently.


Next Article
How to Show a List of Databases in PL/SQL?

R

radheyshavzte
Improve
Article Tags :
  • Databases
  • PL/SQL

Similar Reads

  • How to Show a List of Databases in PL/SQL?
    Managing databases is a fundamental aspect of database administration and development. In Oracle Database, schemas represent logical containers for database objects like tables, views, procedures, and functions. PL/SQL is the procedural extension of and used in Oracle Database and provides powerful
    5 min read
  • How to Open a Database in SQL Server?
    Opening a database in SQL Server is a fundamental task for database administrators and developers. It involves establishing a connection to the server instance and selecting a database to work with. In this article, we will explore two methods to open a database in SQL Server such as using SQL Serve
    3 min read
  • How to Get Database Size in SQL
    SQL database size is important for effective management. It indicates the storage space occupied by tables, indexes, and other components. Knowing the size of a database is useful for various purposes, such as monitoring the growth, estimating the backup time, planning the storage capacity, and opti
    7 min read
  • How to Show/List Tables in MySQL Database
    In MySQL, the SHOW TABLES command is a powerful tool used to list the tables within a specific database. This command provides a convenient way to view the tables that exist in a database without needing to query the database schema directly. In this article, we are going to explore various ways whe
    5 min read
  • SQL - Show Databases
    In the dynamic scene of database management, having a good insight into the available databases for effective administration and development tasks. SHOW DATABASES command is designed to present all databases located on the server. The purpose of exploring the SQL SHOW DATABASES command is to give da
    3 min read
  • How to Show Schema of a Table in MySQL Database?
    A table schema in MySQL database defines the structure of table, including columns, data types, relationships between columns, etc. It is a blueprint for the table, describing how data is organized in the table and how it relates to other tables in the database. To see the schema of a table in MySQL
    2 min read
  • How to Show a List of All Databases in MySQL
    MySQL is a popular open-source relational database management system (RDBMS) that is uniquely used to construct expandable and high-productivity databases. MySQL, which was created by MySQL AB and later acquired by its current owner Oracle Corporation, was originally introduced in 1995. MySQL is rep
    7 min read
  • How to Export Schema Without Data in PL/SQL?
    In database management, there are times when you need to export the structure of your database objects such as tables, views, and procedures without including the data. This can be useful for creating backups, migrating databases, setting up development or testing environments, or sharing your schem
    4 min read
  • How to List all Databases in the Mongo Shell?
    Knowing how to list databases in MongoDB is an important part of managing your data effectively. By using basic MongoDB shell commands, you can easily see what databases you have and understand their sizes. By using commands such as show dbs and db.stats() and users can gain valuable insights into t
    4 min read
  • SQL Server Show/List Databases
    Listing all databases in SQL Server is a common task for database administrators and developers. SQL Server provides two main methods to solve this such as using SQL commands and using SQL Server Management Studio (SSMS). In this article, we will learn about how to Show/List the SQL Server Databases
    4 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences