






Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!







PL/SQL Composite Data Types: Records–Tables–arrays. Named Blocks: Procedures– Functions Packages –Triggers–Data Dictionary Views.
1. Composite Data Types in PL/SQL Definition: 1. Composite data types are used to store multiple values together in a single variable. 2. They can hold different types of data elements. 3. They are useful for handling complex data structures. 4. PL/SQL provides user-defined composite data types. 5. The main composite data types are Records, Tables, and Arrays. Types of Composite Data Types: 1. Records 2. PL/SQL Tables 3. Arrays Example: DECLARE TYPE student_record IS RECORD ( roll_no NUMBER, name VARCHAR2(20) ); student student_record; BEGIN student.roll_no:=101; student.name:='Rahul'; END; / 2. Records in PL/SQL Definition: 1. A record is a composite data type that stores related data items together. 2. A record contains multiple fields with different data types.
Syntax: TYPE table_name IS TABLE OF datatype INDEX BY BINARY_INTEGER; variable_name table_name; Example: DECLARE TYPE names_table IS TABLE OF VARCHAR2(20) INDEX BY BINARY_INTEGER; names names_table; BEGIN names(1):='Rahul'; names(2):='Anu'; DBMS_OUTPUT.PUT_LINE(names(1)); END; / Output: Rahul
5. Operations on PL/SQL Tables Definition: 1. PL/SQL tables support various operations for managing data. 2. Elements are accessed using indexes. 3. Values can be inserted, updated, and deleted. 4. Collection methods are used to manage table data. 5. They provide efficient data processing. Important Methods: Method Purpose FIRST Returns first index LAST Returns last index NEXT Returns next index DELETE Deletes elements COUNT Counts elements
Example: DECLARE TYPE emp_table IS TABLE OF VARCHAR2(20) INDEX BY BINARY_INTEGER; emp emp_table; BEGIN emp(1):='John'; emp(2):='Smith'; DBMS_OUTPUT.PUT_LINE(emp.COUNT); END; / Output: 2
6. Arrays in PL/SQL Definition: 1. Arrays store multiple values of the same data type. 2. Each value is identified using an index number. 3. They allow easy access to stored elements. 4. Arrays are useful for processing large amounts of data. 5. PL/SQL arrays are implemented using collections. Features: Store similar data elements. Accessed by index. Faster data processing. Reduces repeated variables. Supports collection operations. Syntax: TYPE array_name IS VARRAY(size) OF datatype; variable_name array_name; Example:
RETURN value; END; / Example: CREATE OR REPLACE FUNCTION get_square(num NUMBER) RETURN NUMBER IS BEGIN RETURN num*num; END; / Calling function: SELECT get_square(5) FROM dual; Output: 25
10. Packages in PL/SQL Definition: 1. A package is a collection of related procedures, functions, variables, and cursors. 2. Packages are stored as database objects. 3. They provide modular programming. 4. Packages contain specification and body. 5. They improve security and performance. Components: 1. Package Specification 2. Package Body Syntax: CREATE PACKAGE package_name
CREATE OR REPLACE TRIGGER check_insert BEFORE INSERT ON STUDENT BEGIN DBMS_OUTPUT.PUT_LINE('Record Inserted'); END; /
12. Data Dictionary Views Definition: 1. Data dictionary contains information about database objects. 2. It stores metadata about tables, users, procedures, and privileges. 3. Oracle automatically maintains data dictionary information. 4. Users can access information through dictionary views. 5. It helps administrators manage databases. Common Data Dictionary Views: View Purpose USER_TABLES Information about tables USER_OBJECTS Database objects USER_PROCEDURES Stored procedures USER_TRIGGERS Triggers USER_SOURCE PL/SQL source code Example: Display tables: SELECT TABLE_NAME FROM USER_TABLES; Display procedures: SELECT OBJECT_NAME FROM USER_OBJECTS WHERE OBJECT_TYPE='PROCEDURE';