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.
CURSOR C1 IS
SELECT DEPARTMENT_ID,
DEPARTMENT_NAME,
LOCATION_ID
FROM DEPARTMENTS;
REC1 C1%ROWTYPE;
-- Use %TYPE in field declarations to avoid problems if
-- the column types change.
TYPE DEPTREC2 IS RECORD(DEPT_ID DEPARTMENTS.DEPARTMENT_ID%TYPE,
DEPT_NAME DEPARTMENTS.DEPARTMENT_NAME%TYPE,
DEPT_LOC DEPARTMENTS.LOCATION_ID%TYPE);
REC2 DEPTREC2;
-- 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.
TYPE DEPTREC3 IS RECORD(DEPT_ID NUMBER,
DEPT_NAME VARCHAR2(14),
DEPT_LOC VARCHAR2(13));
REC3 DEPTREC3;
BEGIN
NULL;
END;
/
Using %ROWTYPE to Declare a Record
0 comments:
Post a Comment