DEFINING and DECLARING A PL/SQL RECORD:
a) To create a Recoed, we define a RECORD type and then declare Records of that Type.
* TypeName -> is the name of the RECORD Type.
* FieldName -> it is the Name of the field within the Record.
* FieldType -> is the datatype of the Field.
* Expr -> it is the FieldType or an initial value.
b) The NOTNULL Constraint prevents the assigning of NULL's to those fields.
c) Field declaration are like variable declarations each field has a Unique Name aand a specific datatype.
d) The most important point to note is we must create the datatype first and then declare an identifier using the datatype.
Example:
SQL > DECLARE
TYPE EmpRecordType IS RECORD
(
EMpno NUMBER(4) NOT NULL:=500,
EName Emp.EName%TYPE;
Job Emp.Job%TYPE;
);
EmpRecord EmpRecordType;
e) Fields in a record are accessed by Name.
f) To reference of initialize an individual field, we must use dot notation.
RecordName.FieldName
Example:
SQL > DECLARE
V_Empno NUMBER(4):=&EnterEmpmno;
TYPE EmpRecordType IS RECORD
(
V_EName VARCHAR2(30),
V_Deptno NUMBER(2),
V_Job VARCHAR2(20),
);
EmpRecord EmpRecordType;
BEGIN
SELECT EName, Deptno, Job INTO
EmpRecord.V_Ename,
EmpRecord.V_Deptno,
EmpRecord.V_Job
FROM EMP WHERE Empno=V_Empno;
DBMS_OUTPUT.PUT_LINE('Employee Name' || EmpRecord.V_EName);
DBMS_OUTPUT.PUT_LINE('Employee Department' || EmpRecord.V_Deptno);
DBMS_OUTPUT.PUT_LINE('Employee Designation'|| EmpRecord.V_Job);
END;
[8:15 PM
|
0
comments
]



0 comments
Post a Comment
Do comment to make this blog better