Records with UPDATE Statement

In PL/SQL, records are used with UPDATE statements is update the existing data in the database tables. Records are allowed to be organized and manipulate the data in a structured manner. It will make the work with many fields as a single unit.

DECLARE
-- Define a record type
TYPE employee_record_type IS RECORD (
emp_id employees.employee_id%TYPE,
emp_name employees.employee_name%TYPE,
emp_salary employees.salary%TYPE
);

-- Declare a record variable
emp_rec employee_record_type;

BEGIN
-- Assign values to the record fields
emp_rec.emp_id := 101;
emp_rec.emp_name := 'John Doe';
emp_rec.emp_salary := 55000; -- Updated salary

-- Update data in the employees table using the record
UPDATE employees
SET employee_name = emp_rec.emp_name,
salary = emp_rec.emp_salary
WHERE employee_id = emp_rec.emp_id;

-- Commit the transaction
COMMIT;
END;
/



Here, in the above INSERT and UPDATE Statements examples:

  • we can define the record type ’employee_record_type’ that matches with the structure of the ’employee’ table.
  • A record variable ‘emp_rec‘ is declared as ’employee_record_type’.
  • The values are assigned to the fields of the variables of the record.
  • For the INSERT statement, we can use record fields directly in the values of the table.
  • For the UPDATE statement, we can use record fields to update the corresponding columns in the table.

PL/SQL Records

PL/SQL stands for Procedural Language/Structured Query Language. It is an extension of the Structured Query Language (SQL). SQL is used in the Oracle databases for procedural programming. The main feature of PL/SQL is it can work with the composite data types, like records. PL/SQL records can be provided the binding the data into a single unit. It consists of multiple fields and each field has its data type and its name, it defines the structure of the record. These records are declared at the package, block, or schema level. PL/SQL records are allowed to developers for groups of the data under a single name, creating a structured and manageable way to handle data within the programs.

Similar Reads

PL/SQL Records

Records are nothing but it is allowed to the group of related pieces of data under a single name. Records are also called structures in C language, objects in Java language, and tuples in Python language. They organized the data and managed the data into a structured format, enhancing the code readability and maintainability. Records are the fundamental data structures. It plays an important role in managing the data or organizing the data in programs....

Declaration of records with Table-based records

In database systems, it can declare the records using table-based records. Table-based records are the data structures that resemble the tables or rows in a database table. Each record contains the fields i.e. columns with their corresponding values....

Declaration of Records With Cursor-Based Records

In a database management system, a cursor is an object of the database that is used to manipulate the data or retrieve the data row by row, typically within a procedural language like PL/SQL....

Programmer-Defined Record

A programmer-defined record is also called a user-defined record. It is a data structure created by the programmer to store the pieces of data of different types in a single unit. These records are user-defined. these are not predefined records in a programming language or computer system. These records are defined by the programmer according to the needs of the application. These records are mainly used in programming languages that support the composite data types like structures in C/C++, and classes in Java, Python, and C#....

Referencing a Record’s Field

Referencing a record’s field involves accessing or manipulating the individual components of the record variable in PL/SQL. Records in the PL/SQL are equal to the tuples in the Python programming language. These are allowed to the group of data taken under the single variable name....

Assigning records

Assigning records in PL/SQL involved copying the content from one record variable into another record variable. This process allows the duplicate data stored in the record and it is available for manipulating the data without affecting the original data in the records....

Records with INSERT Statement

In PL/SQL, records are used with INSERT statements is insert data in the database tables. Records are allowed to be organized and manipulate the data in a structured manner. It will make the work with many fields as a single unit....

Records with UPDATE Statement

In PL/SQL, records are used with UPDATE statements is update the existing data in the database tables. Records are allowed to be organized and manipulate the data in a structured manner. It will make the work with many fields as a single unit....

Nested Record

A nested record is nothing but the type of record that is used for the modeling of difficult data structures where the entities have more than one attribute. They helped the organize data hierarchically, will made it easier to manage and manipulate the records within the PL/SQL programs....

Conclusion

In PL/SQL, records are the powerful constructs that play a crucial role in database programming. It enables the developers to manage effective data, enhance the code organization, and build robust and scalable applications within the Oracle ecosystems. These are the fundamental constructs that provide the structured approach to handling and manipulating the data within the Oracle databases. They offered different advantages like modularity, data organization, abstraction, flexibility, hierarchical data modeling, and integration with SQL....