DECLARE
-- Best: use %ROWTYPE instead of specifying each column.
-- Use %ROWTYPE instead of %ROWTYPE because
-- we only want some columns.
-- Declaring the cursor doesn't run the query, so no performance hit.
CURSORC1IS
SELECTDEPARTMENT_ID,
DEPARTMENT_NAME,
LOCATION_ID
FROMDEPARTMENTS;
REC1C1%ROWTYPE;
-- Use %TYPE in field declarations to avoid problems if
-- the column types change.
TYPEDEPTREC2ISRECORD(DEPT_IDDEPARTMENTS.DEPARTMENT_ID%TYPE,
DEPT_NAMEDEPARTMENTS.DEPARTMENT_NAME%TYPE,
DEPT_LOCDEPARTMENTS.LOCATION_ID%TYPE);
REC2DEPTREC2;
-- Final technique, writing out each field name and specifying the type directly,
-- is clumsy and unmaintainable for working with table data.
-- Use only for all-PL/SQL code.
TYPEDEPTREC3ISRECORD(DEPT_IDNUMBER,
DEPT_NAMEVARCHAR2(14),
DEPT_LOCVARCHAR2(13));
REC3DEPTREC3;
BEGIN
NULL;
END;
/

Using %ROWTYPE to Declare a Record
0 comments:
Post a Comment