








































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
rdbms notes for final year students
Typology: Lecture notes
1 / 48
This page cannot be seen from the preview
Don't miss anything!









































COMPOSITE DATA TYPES
● (^) A PL/SQL record is based on
Creating a PL/SQL Record TYPE recordtypename IS RECORD (fieldname1 datatype|variable%TYPE|table.column%TYPE| table%ROWTYPE[[NOT NULL]:=|DEFAULT Expression] [,fieldname2…… ,fieldName3……); recordname recordtypename;
Declaration with the % TYPE attribute TYPE employee_rectype IS RECORD (e_id NUMBER(3) NOT NULL:= e_last employee.Lname%TYPE, e_first employee.Fname%TYPE, e_sal employee.salary%TYPE); employee_rec employee_rectype; ● (^) The NOT NULL constraint can be used for any field to prevent Null values ,
Referencing Fields in a Record ● (^) A field in a record has a name that is given in the RECORD-type definition. ● (^) Cannot reference a field by its name only ,
● (^) A record can be assigned to another record if both record have the same structure. ● (^) A record can be set to NULL ,and
● (^) It is advantageous to use %ROWTYPE ,
Nested Records ● (^) Including a record into another record as a field is called the enclosing record. DECLARE TYPE address_rectype IS RECORD (first VARCHAR2(15), last VARCHAR2(15), street VARCHAR2(25), city VARCHAR2(15), state CHAR(2), zip CHAR(5)); TYPE all_address_rectype IS RECORD (home_address address_rectype, bus_address address_rectype, vacation_address address_rectype); address_rec all_address_rectype;
PL/SQL TABLE ● Single- dimensional structure with a collection of elements that store the same type of value. ●It is like an array in other programming languages. ●A table is a dynamic structure that is not constrained. DECLARING A PL/SQL TABLE ●A PL/SQL TABLE declaration is done in two steps , like a record declaration.
● (^) The table consists of two columns, the index/primary key column and the data column. ● (^) We define the actual table based on the table declared earlier Syntax Table name tabletypename; Example Deptname_table deptname_table_type; Major_table mojor_table type
TABLE STRUCTURE ● (^) Table structure contains a primary key column and a data column.
● (^) Use an expression or a value other then a BINARY_INTEGER value , and PL/SQL will convert it. /25.7 is rounded to 26./** Deptname_table (25.7) := Training; /5’ ||00’ is converted to 500./** Deptname_table (5,||’);:=Research’; / v_num+7 is evaluate./** Deptname_table (v_num+7) :=`Development’;
Assign values to the rows in a table in three ways.