You can use DML to insert, update, and delete records from object tables, in much the same way that you can use it on relational tables.
However, there are some subtle differences, which are listed below:
- An object table may contain a column that is associated with an object type. In such case, you must specify the object type name to insert or update the records.
- Updating a record within an object table requires the use of table name aliases.
- In the case of object tables that contain references to other objects, you must use the REF operator to insert and update the records.
There are two ways to insert and update the records within object tables:
- Specify all the values for inserting or updating the records
- Query within an INSERT or UPDATE statement to perform the DML operation
Modifying object tables in Oracle PL/SQL involves several key concepts that are essential for effective database administration. Understanding these concepts will enable you to manipulate and manage object tables with precision and efficiency. Here's an overview:
- Understanding Object Types: Before modifying object tables, it's crucial to have a thorough understanding of the object types. These are user-defined types that represent real-world entities with their attributes and methods. Each object type defines the structure of the objects (rows) in the table.
- Using the ALTER TYPE Statement: This statement is used to modify an existing object type. It allows you to add or drop attributes and methods. Be cautious, as altering an object type can invalidate dependent tables and routines.
- Object Table Structure: Object tables are created based on object types. Each row in an object table represents an object, and the columns correspond to the attributes of the object type. Understanding this structure is key to effective table modification.
- Inserting and Updating Data: To insert data into an object table, you typically use the `INSERT` statement with the constructor method of the object type. For updating existing data, the `UPDATE` statement is used, where you can set new values for one or more attributes of the object.
- Deleting Data: Data removal from object tables is done using the `DELETE` statement. It's important to consider the impact of deletions on the integrity of the database, especially regarding referential constraints.
- Handling Nested Tables and VARRAYs: If your object type includes nested tables or VARRAYs (variable-size arrays), you need to understand how to manipulate these collections. This includes using the TABLE() operator for nested tables and handling the storage and retrieval of VARRAY elements.
- Referential Integrity and Constraints: Ensure that modifications to object tables do not violate referential integrity. Constraints may need to be added, modified, or dropped to maintain data integrity.
- Performance Considerations: Modifications to object tables, especially large ones, can impact performance. Consider strategies like indexing, partitioning, and appropriate use of PL/SQL for batch updates or modifications.
- Type Inheritance and Polymorphism: If using type inheritance, be aware of how changes to a parent type affect subtypes. Polymorphism can be leveraged for designing more flexible and reusable code.
- Versioning and Evolution of Types: Oracle allows for the evolution of types, where you can version object types to handle changes over time. This is crucial for maintaining compatibility and for applications that require historical data tracking.
- Transaction Management: Modifications to object tables should be appropriately managed within transactions to ensure data consistency and to handle rollback scenarios in case of errors.
- Security and Privileges: Managing security is crucial. Ensure that only authorized users have the necessary privileges to modify object tables, especially in a production environment.
- Backup and Recovery Considerations: Always consider the implications of object table modifications on backup and recovery strategies. Regular backups and understanding how to recover modified object tables are essential.
By mastering these concepts, you can effectively manage and modify object tables in Oracle PL/SQL, ensuring the integrity, performance, and security of your database.
If you perform DML (Data Manipulation Language) actions inside of a Java Stored Procedure, Oracle places these restrictions on how the procedure or function can be used:
- It cannot be called from a SELECT statement or parallelized DML statement.
- It cannot be called from an INSERT, UPDATE, or DELETE statement if the statement modifies the same tables as the Stored Procedure
- It cannot be called from a SELECT, INSERT, UPDATE, or DELETE statement if it performs any transaction management (for example, calling commit() or rollback()). By extension, it cannot execute any DDL (Data Definition Language) statements since these are automatically committed by Oracle.
- It cannot be called from a SELECT, INSERT, UPDATE, or DELETE statement if it performs system or session control functions.
Attempts to violate these restrictions are met with a run-time error. In the next lesson, we will look at writing DML statements to insert records into object tables.